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

狂风中的少年 提交于 2019-12-06 14:41:15

问题


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



来源:https://stackoverflow.com/questions/4574825/how-can-i-load-another-new-word-document-in-the-same-word-window

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