|
本帖最后由 同心/ty 于 2023-2-28 17:01 编辑
请教大师们,我在word文档设置了宏代码,打开word文档就执行宏命令。(代码如下),但有一个你缺点就是,当不想执行宏时也执行了,我想通过对话框形式选择执行宏,还是停止执行宏。网上查了MSGBOX函数,但不知道怎么用。跪求代码。
Sub MsgBox函数()
If MsgBox("单击“是”则执行下一步,“否”打开文件", vbYesNo) = vbYes Then
End If
End Sub
两组代码如何沟通
Sub word文档合并()
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdSectionBreakNextPage
If Selection.PageSetup.Orientation = wdOrientPortrait Then
Selection.PageSetup.Orientation = wdOrientLandscape
Else
Selection.PageSetup.Orientation = wdOrientPortrait
End If
Dim myDialog As FileDialog
Dim i As Long
On Error Resume Next
Set myDialog = Application.FileDialog(msoFileDialogFilePicker)
With myDialog
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "所有 WORD 文件", "*.doc", 1
End With
If myDialog.Show <> -1 Then Exit Sub
For i = 1 To myDialog.SelectedItems.Count
Selection.InsertFile FileName:=myDialog.SelectedItems(i)
Selection.EndKey Unit:=wdStory
Selection.Delete
Next
Selection.EndKey Unit:=wdStory
Selection.Delete
End Sub
|
|