Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make New Document Active (Word 2003 SP1)

    I have this code from an 'OK' button on a form which simply allows the user select to create a New Blank Document, or insert other types of files. The problem area is inserting the new blank document because I need to become the active document. So whatever other documents are open at the time, they need to remain open and go to the background, and the new blank document has to become active.

    Can anyone help with the correct code I need to use and where to use it?

    Thanks
    =======================================
    Private Sub btnOK_Click()
    Dim Today As String, FirstInit As String, Name As String, Dir As String, ChangeDir As String
    Dim NewDoc As Byte

    ChangeDir = Me.lbxProfessionals.Value
    Today = " "
    FirstInit = ChangeDir
    Name = Application.UserInitials
    Order = " "
    Dir = "G:" & ChangeDir & ""
    MakeFileName Today, FirstInit, Order, Dir
    Name = Dir & Today & "_" & Name & Order & ".doc"
    Select Case Choice
    Case 0
    Application.ChangeFileOpenDirectory "F:TEMPLATES"
    Documents.Add Template:="Document", NewTemplate:=True
    Case 1
    Case 2
    Case Else
    End Select
    With Application.Dialogs(wdDialogFileSaveAs)
    .Format = wdFormatDocument
    End With
    If ActiveDocument.SaveFormat = wdFormatTemplate Then
    ActiveDocument.SaveAs FileFormat:=wdFormatDocument
    End If
    ActiveDocument.SaveAs FileName:=Name, FileFormat:= _
    wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
    True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
    False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    SaveAsAOCELetter:=False
    Call LLCreateFooter
    Selection.WholeStory
    Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove
    Unload Me
    End
    End Sub
    =======================================
    Thanks again
    Nick

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Make New Document Active (Word 2003 SP1)

    Normally, when you use Documents.Add, the new document automatically becomes the active document. If that doesn

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    Dim Doc As Word.Document
    Set Doc = Documents.Add

    This creates a blank new document based on Normal.dot. If you want to create a document based on another template, use:
    Set Doc = Documents.Add(Template:="C:FullPathToTemplate.dot" )

    This new document usually is the active document. If it isn't, you can use Doc.Activate if Doc is added/opened before.

  4. #4
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    I tried both ideas (they were similar anyway) without success. It doesn't have the desired effect to activate the new document - the original document remains active.

    Thanks
    Nick

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Make New Document Active (Word 2003 SP1)

    That is strange, but if you set a variable of type Document, you can manipulate it whether it is the active document or not, so it shouldn't matter.

  6. #6
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    I got a bit cranky with it and put this in at the end:

    NewDoc.Activate
    MsgBox NewDoc.Name
    NewDoc.Activate
    NewDoc.Activate

    The message box actually shows the correct document name but it just doesn't activate.

    What if a call a function or something outside of the current procedure to make it switch?

    Thanks
    Nick

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Make New Document Active (Word 2003 SP1)

    If Documents.Add and NewDoc.Activate don't bring the document to the front, other code won't do it either, I'm afraid. I don't understand why this is happening. but again. do you really need the document to be active?

  8. #8
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    Yes the new document does need to be active with any existing documents remaining open.

    Is there a way to count the total number of open documents and move to the first (or last) in the group - whatever the new document happens to be?

    Thanks
    Nick

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Make New Document Active (Word 2003 SP1)

    You could try

    Windows(Windows.Count).Activate

    but since Activate doesn't seem to behave as it should, I don't know whether it will work. Still, it won't take long to test.

  10. #10
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    That didn't work either.

    What about closing the new document then reopening the same, as the most recently used document?

    Something's gotta work!

    Thanks
    Nick

  11. #11
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    Success!! Here's what worked:

    Call LLCreateFooter
    NewDoc.ActiveWindow.Selection.WholeStory
    NewDoc.ActiveWindow.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove
    Unload Me

    ActiveDocument.SaveAs FileName:=Name, FileFormat:= _
    wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
    True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
    False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    SaveAsAOCELetter:=False

    NewDoc.Close
    RecentFiles(1).Open
    End
    ==============================

    Strange but true!

    Thanks for all your ideas and help.

  12. #12
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Make New Document Active (Word 2003 SP1)

    Hello loungers

    The windows in task bar setting seems to make a difference.

    I am having a similar issue with Word 03 and turning the setting off seems to help.
    The new document is active.

    Geof

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Make New Document Active (Word 2003 SP1)

    It is possibly related to your form? Modal, and all that.
    In 97/2000/2002/2003 I've never had a problem with activating or making visible a document except when I'm still in a form, and the form won't let Word get back to treating documents until the form is hidden or unloaded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •