经过高手的指导,上述问题已解决,谢谢!但是新的问题产生了:程序执行后,出现提示:是否保存对“BOOK3.XLS”的更改?,之后我又将activeworkbook.save加上去,可还是不行,请高手指点,该怎样实现对XLS文件的自动保存?总的程序如下:
Private Sub CommandButton1_Click() ' 安全创建选择集 On Error Resume Next Dim SSet As AcadSelectionSet If Not IsNull(ThisDrawing.SelectionSets.Item("Example")) Then Set SSet = ThisDrawing.SelectionSets.Item("Example") SSet.Delete End If Set SSet = ThisDrawing.SelectionSets.Add("Example") Dim fType As Variant, fData As Variant ' 选择集过滤器 Call CreateSSetFilter(fType, fData, 2, "title") SSet.Select acSelectionSetAll, , , fType, fData '获取TITLE信息 Dim Cnt As Integer Dim ssss As String ssss = "" Dim exltagname_1 As String Dim acadBlkTitleRef As AcadBlockReference Dim acadAttrTitle As AcadAttribute Dim varAttributes As Variant Set acadBlkTitleRef = SSet.Item(0) varAttributes = acadBlkTitleRef.GetAttributes For Cnt = LBound(varAttributes) To UBound(varAttributes) Select Case varAttributes(Cnt).TagString Case "TITLE-CN-1" exltagname_1 = varAttributes(Cnt).TextString Case "TITLE-CN-2" exltagname_2 = varAttributes(Cnt).TextString Case "TITLE-CN-3" exltagname_3 = varAttributes(Cnt).TextString Case "TITLE-CN-4" exltagname_4 = varAttributes(Cnt).TextString End Select Next MsgBox exltagtag ' 删除选择集 SSet.Delete On Error Resume Next Set xlapp = GetObject(, "excel.application") If Err Then Err.Clear Set xlapp = CreateObject("excel.application") If Err Then Err.Clear MsgBox ("不能运行EXCEL,请检查是否安装了EXCEL") Exit Sub End If End If
xlapp.workbooks.Open "D:\book3.xls" Set xlsheet = xlapp.activesheet xlsheet.range("A2").Value = exltagname_1 activeworkbook.Save xlapp.Quit Set xlsheet = Nothing Set xlbook = Nothing Set xlapp = Nothing End Sub
另外一个问题,exltagname_1的值总是传不出来,故EXCEL文件中A2的值未更改。且用MSGBOX exltagname_1都显示不出他的值。但是exltagname_1对应的varAttributes(0).TextString的值却能够显示出来!请问为什么,该怎样解决?谢谢!
|