|
楼主 |
发表于 2023-5-8 21:54
|
显示全部楼层
Private Sub CommandButton2_Click()
Dim objApp As Object 'Word.Application
Dim objDoc As Object 'Word.Document
Dim strTemplates As String '模板文件路径名
Dim strFileName As String '将数据导出到此文件
Dim i As Integer
Dim side_A As String
Dim side_B As String
Dim side_C As String
i = ActiveCell.Row
side_A = CStr(Format(Cells(i, 1), "000"))
side_B = Cells(i, 2)
side_C = Cells(i, 6)
side_d = Cells(i, 15)
If Cells(i, 16) <> "" Then
side_E = "(" & Cells(i, 16) & ")"
End If
side_F = Cells(i, 17)
If Cells(i, 18) <> "" Then
side_G = "/"
End If
side_H = Cells(i, 18)
If Cells(i, 19) <> "" Then
side_i = "(" & Cells(i, 19) & ")"
End If
side_J = Cells(i, 20)
side_K = Cells(i, 30)
side_L = Cells(i, 31)
side_M = Cells(i, 32)
side_N = Cells(i, 33)
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Add "word文件", "*.doc*", 1
.AllowMultiSelect = False
If .Show Then strTemplates = .SelectedItems(1) Else Exit Sub
End With
'通过文件对话框生成另存为文件名
With Application.FileDialog(msoFileDialogSaveAs)
'.InitialFileName = CurrentProject.Path & "\" & side_d & ".doc"
.InitialFileName = side_d & ".doc"
If .Show Then strFileName = .SelectedItems(1) Else Exit Sub
End With
'文件名必须包括“.doc”的文件扩展名,如没有则自动加上
If Not strFileName Like "*.doc" Then strFileName = strFileName & ".doc"
'如果文件已存在,则删除已有文件
If Dir(strFileName) <> "" Then Kill strFileName
'打开模板文件
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
Set objDoc = objApp.Documents.Open(strTemplates, , False)
请大侠帮我看一下下,这里帮我改一下下看 |
|