It seems that in the Microsoft Word object model, a Word document is bound to a Window, but I want to close the existing document and open a new one without closing the Word window. How can I do this?
问题:
回答1:
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
回答2:
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.
回答3:
Ctrl+w (to close current window) and then Ctrl+n (to open new one)
Two Key Taps, thats all :)
回答4:
Isn't it .close?
.exit quits the whole application?
回答5:
Temporarily use
Application.ShowWindowsInTaskbar = False
Which effectively makes Word into an MDI style application.
回答6:
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
回答7:
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