Activate Document

S

singeredel

Two documents are created with the variable names "SaveNotesFile" and
"SaveFileName". SaveNotesFile is active and showing on the screen. The next
code is attempting to activate SaveFileName, as follows:

Documents(SaveFileName).Activate

When hovering over this code while stepping through the code, the correct
file name is showing in the SaveFileName variable, but the screen does not
actually switch the view to this file so that more action can be taken on
this file.

What am I doing wrong here? How do I get SaveFileName to show as active on
the screen? (I am NOT a programmer, so if you can answer this in layman's
terms, I would really appreciate it!)

Below is a portion of the code from the programming that pertains to when
this code seems to bomb out. It does not seem to do anything after the
"ActiveDocument.SaveAs (SaveNotesFile)" line right before the EndProcedure:

MakeNotesFile:
Dim TestFile1 As String
TestFile1 = Dir(SaveNotesFile)
If Len(TestFile1) = 0 Then
Documents.Add Template:="Normal", NewTemplate:=False
Selection.Style = ActiveDocument.Styles("Normal2")
With Selection.Font
.AllCaps = True
.Bold = True
End With
Selection.TypeText Text:="NOTES:"
Selection.TypeParagraph
Selection.TypeText Text:=Doctor + " - " + DictationDate2
Selection.TypeParagraph
Selection.TypeParagraph
With Selection.Font
.Bold = False
.AllCaps = False
End With
Selection.TypeText "None."
ActiveDocument.SaveAs (SaveNotesFile),
FileFormat:=wdFormatDocument
Else: GoTo EndProcedure
End If
EndProcedure:
Documents(SaveFileName).Activate
With ActiveDocument.ActiveWindow
ActiveWindow.View.Type = wdNormalView
ActiveWindow.ActivePane.View.Zoom.Percentage = 130
.DisplayRulers = True
End With
 
D

DaveLett

Hi singeredel,

Without seeing where or how you set you variables for the documents, it's
difficult (for me, at least) to be certain where your issue is. However, you
don't need to use activate to make these changes to a document. That is, you
can use something like the following:

Dim oDoc As Document
Set oDoc = Documents("Document3") '''the name of your document
With oDoc.ActiveWindow
.View.Type = wdNormalView
.ActivePane.View.Zoom.Percentage = 130
.DisplayRulers = True
End With

HTH,
Dave
 
S

singeredel

Thank you for your prompt answer, but the SaveFileName document needs to be
the active visible document on the screen at this point because that is where
the editing needs to take place by the user from this point on. In addition,
the code following this activation point that changes the view percentage to
130% etc. is being done on the wrong document because the correct document is
not active on the screen. It is changing the SaveNotesFile document, which is
not the intended document for this action.

Because the entire coding is to too long and complicated to copy here or to
even try to explain, the only thing I can tell you is that the program works
fine up to this point. Those same variable names are being used at other
points in the program without a problem.
 
F

Fumei2 via OfficeKB.com

It certainly is correct that it is better to use explicit document objects,
rather than names from the documents collection. It is always better to be
explicit, and generally better to use objects.

If Len(TestFile1) = 0 Then

seems a little odd.

Are you says that the code following that does execute? You DO get a
document using the SaveAs?
 
S

singeredel

All of that coding has worked for a long time (years) -- even the activate
command. For some reason it just quit working and I can't figure out why.
 
S

singeredel

The SaveFileName variable contains the document name, such as "Test20100119.
With a prior small change I made in the program, the ".doc" extension did not
get into the file name variable anymore. When I fixed this, the correct
document came to the forefront of the screen and the rest of the changes
occurred on the correct document.

I cut and paste your code into my program to replace what I had before and
it didn't seem to correct the problem with bringing the correct document to
the forefront of the screen. It did, however, make the changes to the correct
document as far as changing the view size, etc.
 
S

singeredel

As an aside, I want the correct document to be displayed in the forefront of
the screen, not just to have changes made to it in the background, so it is
important to have the correct document on top.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top