基于VB语言的EXCEL和CST以及AutoCAD与ANSYS等的二次开发

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于VB语言的EXCEL、CST以及HFSS等的二次开发

代码1:vb创建xls表,并写入内容

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象Set ExcelBook = ExcelApp.Workbooks.Add

Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页ExcelSheet.Activate '激活工作页

ExcelApp.DisplayAlerts = False

="sheet1"

ExcelSheet.Range("A1").Value = 100 '设置A1的值为100

ExcelBook.SaveAs "d:\test.xls" '保存工作表

msgbox "d:\test.xls创建成功!"

ExcelBook.close

set excelApp=nothing

set ExcelBook=nothing

set ExcelSheet=nothing

将以上代码copy到记事本存为"writexls.vbs"文件,可运行测试

代码2:读execel文件

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象Set ExcelBook = ExcelApp.Workbooks.open("d:\test.xls")

Set ExcelSheet = ExcelBook.Worksheets(1)

msgbox ExcelSheet.Range("A1").Value

将以上代码copy到记事本存为"readxls.vbs"文件,可运行测试

代码3:上述代码联合调试

Dim ExcelApp,ExcelBook,ExcelSheet

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象Set ExcelBook = ExcelApp.Workbooks.Add

Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页ExcelSheet.Activate '激活工作页

ExcelApp.DisplayAlerts = False

="sheet1"

ExcelSheet.Range("A1").Value = 100 '设置A1的值为100

ExcelBook.SaveAs "D:\Study\VBS\Book1.xls" '保存工作表

msgbox "d:\Book1.xls创建成功!"

ExcelBook.close

set excelApp=nothing

set ExcelBook=nothing

set ExcelSheet=nothing

'ExcelApp.WorkBooks.Close

'ExcelApp.Quit

Set ExcelApp = CreateObject("Excel.Application")

ExcelApp.Visible = True

'创建EXCEL对象

Set ExcelBook = ExcelApp.Workbooks.open("D:\Study\VBS\Book1.xls")

Set ExcelSheet = ExcelBook.Worksheets(1)

msgbox ExcelSheet.Range("A1").Value

ExcelApp.WorkBooks.Close

ExcelApp.Quit

若对支持VB脚本的软件进行二次开发,上述描述有借鉴意义。例如CST,HFSS 等电磁软件(以及AutoCAD,ANSYS等)就可如此外部调用。

代码4:VBS调用CST进行运算

Dim app

Set app = CreateObject("CSTStudio.Application")

Dim mws

Set mws = app.OpenFile("D:\VBS\1.cst")

'mws.Visible = False

With mws

.DeleteResults

.Rebuild

.Solver.Start

.Save

End With

mws.Quit

代码5:VBS调用CST进行运算

Dim fs

Set fs =createobject("scripting.filesystemobject")

Dim ts

Set ts=fs.opentextfile("opt.txt",1,true)

Dim path

path=ts.readall

ts.close

'msgbox path

Dim app

Set app = CreateObject("CSTStudio.Application")

Dim mws

Set mws = app.OpenFile(path)

Dim chang

Dim kuan

Dim gao

'Dim result(30)

Set ts=fs.opentextfile("chang1.txt",1,true)

chang=ts.readline

相关文档
最新文档