[英]Opening Word Document From Excel
當我單擊 excel 電子表格中的按鈕時,我試圖使用 VBA 打開特定的 word 文檔。 我想把 go 寫入文件。 然后我想將 window 的大小更改為“Restore Down”。 本質上,單詞 window 應該是彈出框的大小。 當我運行 VBA 時,我只是有時會被帶到 word 文檔。 Word 圖標的 rest 剛出現在我的 windows 菜單欄上並閃爍。 我在 Word 中的 VBA 完全沒有任何作用。 我在下面顯示了我的 Word 和 Excel VBA。
My VBA in Excel
Private Sub CommandButton3_Click()
Set wordapp = CreateObject("word.Application")
wordapp.documents.Open "C:\Users\rossy\OneDrive\Work In Progress\Payroll and Billing
Spreadsheet\Newest 148\Code\1.docx"
wordapp.Visible = True
wordapp.Application.Activate
End Sub
My VBA In Word
Private Sub Document_Open()
With Application
.WindowState = wdWindowStateNormal
.Resize Width:=InchesToPoints(5), Height:=InchesToPoints(5)
End With
End Sub
如果你只想調整Word window的大小,我會去掉你Word文檔中的vba代碼,將其添加到Excel vba代碼如下:
Private Sub CommandButton3_Click()
Set wordapp = CreateObject("word.Application")
On Error GoTo OpenedErr
Set doc = wordapp.documents.Open("C:\Users\rossy\OneDrive\Work In Progress\Payroll and Billing Spreadsheet\Newest 148\Code\1.docx")
wordapp.Application.WindowState = wdWindowStateNormal
wordapp.Application.Resize Width:=400, Height:=400
wordapp.Visible = True
wordapp.Application.Activate
OpenedErr:
' Don´t forget to clean memory once done
Set doc = Nothing
Set wordapp = Nothing
End Sub
請嘗試此操作,看看它是否可以正確打開而不閃爍(在我的 PC 中它打開 Word 應用程序並激活它,我無法重現您提到的閃爍行為)。
如果這解決了您的問題,請將其標記為答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.