0

下面是我的代码,我的问题是我想在创建文档时输入我想要的文件名。但我不知道怎么做。你能帮助我吗。

这是我的代码:

    Dim oWord As Word.Application
    Dim odoc As Word.Document
    Dim oWModule As VBIDE.VBComponent
    Dim sCode As String
    Dim oCommandBar As Office.CommandBar
    Dim oCommandBarButton As Office.CommandBarControl


    ' Create an instance of Word, and show it to the user.
    oWord = New Word.Application()

    ' Add a Document.
    odoc = oWord.Documents.Add

    ' Create a new VBA code module.
    oWModule = odoc.VBProject.VBComponents.Item("ThisDocument")

    sCode = "Sub FileSaveAs" & vbCr & _
       "   msgbox ""Save As has been Disabled!"" " & vbCr & _
       "end sub"

    ' Add the VBA macro to the new code module.
    oWModule.CodeModule.AddFromString(sCode)

    oWord.Visible = True
    ' Set the UserControl property so that Excel does not shut down.
    'oWord.UserControl = True

    ' Release the variables.
    oCommandBarButton = Nothing
    oCommandBar = Nothing
    oWModule = Nothing
    odoc = Nothing
    oWord = Nothing

    ' Force garbage collection.
    GC.Collect()
4

2 回答 2

0

添加文档后可以运行 odoc.saveas 吗?在 Powerpoint 中,分配文件名-

于 2012-10-05T09:41:48.263 回答
0

添加代码行

' Add a Document.
    odoc = oWord.Documents.Add
    odoc.Name = "DesiredNameHere"

重命名word文档。

于 2012-10-05T13:31:35.270 回答