PDA

View Full Version : Close active document and open "mydocument.doc"



hunsnowboard
03-22-2009, 10:10 AM
Hi there Everyone! My problem probably is very easy but I cannot find the solution! :(

I have a form with a command button. Once the command button is pressed I would like to happen the following:

1. close the active document (without saving)
2. open the "mydocument.doc" document which is in the same directory

So far this is the code but it does not work:

Private Sub next_Click()
Unload Me
ThisDocument.Close

Dim wordfile1 As String
wordfile1 = ThisDocument.Path & "\mydocument.doc"
Documents.Open wordfile1
End Sub

The problem is that I get a blank screen with ms word application open, but no document opened. :( Why is that happening? Please try to help if you can! Thank you in advance!

lucas
03-22-2009, 10:57 AM
move your thisdocument.close down below the document.open worfile1 works for me......

The way you have it in your post #1 it is closing the document so it can't run the rest of the code....

fumei
03-23-2009, 10:56 AM
Private Sub next_Click()
Unload Me
ThisDocument.Close

Once you execute Unload Me...then it is unloaded..and no further instructions will execute. How could they? The userform is unloaded.

"I have a form with a command button. Once the command button is pressed I would like to happen the following:

1. close the active document (without saving)"

Critical question here: where are you running the userform from? Hopefully not the ActiveDocument!

I strongly recommend you use Document objects and Set them explicitly. That way, you can always be very very specific about what document you are working with.