excel vba 提示424错误“要求对象” 5
PrivateSubCommandButton1_Click()DimiDimFilePathAsStringFilePath=ThisWorkbook.Path&"\1...
Private Sub CommandButton1_Click()
Dim i
Dim FilePath As String
FilePath = ThisWorkbook.Path & "\1.0.docm"
Set Table = Sheets("封皮").UsedRange()
Dim WordFile As Object
Set WordFile = GetObject(FilePath)
Set WordFile = CreateObject("Scripting.FileSystemObject")
For i = 2 To Table.Rows.Count
For Each Var In ActiveDocument.Variables
Var.Delete
Next
ActiveDocument.Variables.Add Name:="Project", Value:=Table.Cells(i, 1).Text
ActiveDocument.Variables.Add Name:="Phase", Value:=Table.Cells(i, 2).Text
ActiveDocument.Variables.Add Name:="ProjectNo", Value:=Table.Cells(i, 3).Text
ActiveDocument.Variables.Add Name:="SubItem", Value:=Table.Cells(i, 4).Text
ActiveDocument.Variables.Add Name:="SubItemNo", Value:=Table.Cells(i, 5).Text
ActiveDocument.Variables.Add Name:="Title", Value:=Table.Cells(i, 6).Text
ActiveDocument.Variables.Add Name:="DwgNo", Value:=Table.Cells(i, 7).Text
ActiveDocument.Variables.Add Name:="VerNo", Value:=Table.Cells(i, 8).Text
ActiveDocument.Variables.Add Name:="Sheet", Value:=Table.Cells(i, 9).Text
ActiveDocument.Variables.Add Name:="Major", Value:=Table.Cells(i, 10).Text
ActiveDocument.Fields.Update
ActiveDocument.SaveAs ThisWorkbook.Path
ActiveDocument.SaveAs Filename:="第" & Table.Cells(i, 8).Text & "版" & Table.Cells(i, 16).Text & "-" & Table.Cells(i, 6).Text & ".doc"
Next
'
End Sub 展开
Dim i
Dim FilePath As String
FilePath = ThisWorkbook.Path & "\1.0.docm"
Set Table = Sheets("封皮").UsedRange()
Dim WordFile As Object
Set WordFile = GetObject(FilePath)
Set WordFile = CreateObject("Scripting.FileSystemObject")
For i = 2 To Table.Rows.Count
For Each Var In ActiveDocument.Variables
Var.Delete
Next
ActiveDocument.Variables.Add Name:="Project", Value:=Table.Cells(i, 1).Text
ActiveDocument.Variables.Add Name:="Phase", Value:=Table.Cells(i, 2).Text
ActiveDocument.Variables.Add Name:="ProjectNo", Value:=Table.Cells(i, 3).Text
ActiveDocument.Variables.Add Name:="SubItem", Value:=Table.Cells(i, 4).Text
ActiveDocument.Variables.Add Name:="SubItemNo", Value:=Table.Cells(i, 5).Text
ActiveDocument.Variables.Add Name:="Title", Value:=Table.Cells(i, 6).Text
ActiveDocument.Variables.Add Name:="DwgNo", Value:=Table.Cells(i, 7).Text
ActiveDocument.Variables.Add Name:="VerNo", Value:=Table.Cells(i, 8).Text
ActiveDocument.Variables.Add Name:="Sheet", Value:=Table.Cells(i, 9).Text
ActiveDocument.Variables.Add Name:="Major", Value:=Table.Cells(i, 10).Text
ActiveDocument.Fields.Update
ActiveDocument.SaveAs ThisWorkbook.Path
ActiveDocument.SaveAs Filename:="第" & Table.Cells(i, 8).Text & "版" & Table.Cells(i, 16).Text & "-" & Table.Cells(i, 6).Text & ".doc"
Next
'
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询