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

コード行を追加します

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

Word ドキュメントの名前を変更します。

于 2012-10-05T13:31:35.270 に答える
0

ドキュメントを追加した後に odoc.saveas を実行できますか? パワーポイントでは、ファイル名を割り当てます-

于 2012-10-05T09:41:48.263 に答える