How can I load another new Word document in the same Word window?

对着背影说爱祢 提交于 2019-12-04 19:21:17

This works for me to close a document and open a document in the same window (I'm running the macro from normal.dotm):

Sub CloseOpenSameWindow()
    Dim d As Document: Set d = ActiveDocument
    Application.ScreenUpdating = False
    d.Close
    Application.Documents.Add Template:="C:\Users\Me\Desktop\Mydocument.docx"
    Application.ScreenUpdating = True
End Sub

Have you tried File->Close ? That should close the file and leave the window open, allowing you to open another file in the same window, atleast thats how I remember it working.

Ctrl+w (to close current window) and then Ctrl+n (to open new one)

Two Key Taps, thats all :)

Isn't it .close?

.exit quits the whole application?

Temporarily use

Application.ShowWindowsInTaskbar = False 

Which effectively makes Word into an MDI style application.

You should consider the following for implementing your add-in:

  • The add-in should not depends on the window mode (SDI or MDI)
  • The add-in state should be saved to retain user customizations. Saving add-in state can be achieved by using XML, registry, INI or any other format.
  • Every time a document is open the add-in should change to reflect the document state.
  • The add-in should support multiple word Document instances.

See:

http://www.visualstudiodev.com/visual-studio-tools-for-office/word-addin-multiple-instances-of-word-running-48076.shtml

http://msdn.microsoft.com/en-us/library/aa189710(v=office.10).aspx

try this

in the Normal.ThisDocument

Sub main()
    Me.Close
    Documents.Add
End Sub

this will close the current document and open a new document. you need to handle the save for current document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!