-1
任何人都可以指出我做錯了什麼。我試圖向Word輸出一個Access 2007報告(使用.rtf!),但我似乎無法將我的代碼指向該文件。我不斷收到類型不匹配錯誤。
這裏是我的代碼:使用Access 2007 VBA創建和打開Word文檔
Private Sub CatalogTitle_Click()
Dim AppWord As Object
Dim Doc As Object
Dim FileName As String
Dim DateTime As Date
Dim DTString As String
Dim x As Integer
Set AppWord = CreateObject(Class:="Word.Application") ' create an instance of Word
DateTime = Now() ' build a date string which is compatible with the Windows File structure
DTString = CStr(DateTime)
For x = 1 To Len(DTString) ' changes dd/mm/yy hh:mm:ss into dd_mm_yy hh_mm_ss
If (Mid(DTString, x, 1) = "/" Or Mid(DTString, x, 1) = ":") Then
Mid(DTString, x, 1) = "_"
End If
Next x
' build the full .rtf filename
FileName = "Titles " & DTString & ".rtf"
' and output the rtf file to it
DoCmd.OutputTo acReport, "ItemsReportByTitle", acFormatRTF, FileName
' then open the Word instance with the file just created
Set Doc = "AppWord.Documents.Open(FileName)"
' and make the instance visible
AppWord.Visible = True
End Sub
我一直沒有在「設置文檔...」線。
哇!這產生了巨大的差異。謝謝! – Solong
是的 - 你正在分配一個字符串,這不適用於'Set