open "Print Layout" in word by code (1 Viewer)

24sharon

Registered User.
Local time
Today, 03:26
Joined
Oct 5, 2004
Messages
147
In the menu in word there is some option to view the documents
1. Normal
2. Print Layout
3….


I open the word’s document from the access
I insert value from the access into word.

I asked here some question in last week and I helped so much.

My question now is:

In the document in the word I put some bookmarks.
One of the bookmarks is on the header (Title of the document)

And then when I open the document its open in a “Normal” view
I want to open the document in “Print Layout”

Can I open a document in “Print Layout” by code?

The problem code is:
objWord.ActiveDocument.Bookmarks("nivchan").Select
objWord.Selection.Text = Me.M_NIVHAN
Because the Bookmark: “nivchan” is on the header.

Thanks a lot and good week!
 

boblarson

Smeghead
Local time
Today, 03:26
Joined
Jan 12, 2001
Messages
32,059
Just a hint - Go into Word, set the view to Normal, record a new macro and set it to print view. Stop the record and go into the Visual Basic Editor in Word and open the macro up and look at it.

Your code will likely be exactly the same as it used there, or may need just a slight tweaking.

That method of getting some code to use in Access while working with the COM objects of the other program will work for most of the Office products. It's something I use frequently.
 

24sharon

Registered User.
Local time
Today, 03:26
Joined
Oct 5, 2004
Messages
147
first of all thanks!

this trick is new for me and its a butiful!

I try to do and I got an error

here is my code:
Code:
Private Sub m1_Click()
Dim objWord
Set objWord = CreateObject("word.application")
objWord.Visible = True
objWord.Documents.Add DocumentType:=wdNewBlankDocument 'new document
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////
    If objWord.ActiveWindow.View.SplitSpecial = wdPaneNone Then
        objWord.ActiveWindow.ActivePane.View.Type = wdPrintView
    Else
        objWord.ActiveWindow.View.Type = wdPrintView
    End If
'//////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub

and the error on the attach image

how can I fixed it?

thanks again
 

Attachments

  • 111.JPG
    111.JPG
    78.1 KB · Views: 242

boblarson

Smeghead
Local time
Today, 03:26
Joined
Jan 12, 2001
Messages
32,059
Try setting a reference to Word, in Tools / References. It worked for me after I did that.
 

24sharon

Registered User.
Local time
Today, 03:26
Joined
Oct 5, 2004
Messages
147
thanks! I'll try

and if I missing the reference of word, can I copy the file from other computer and insert into my computer?
 

boblarson

Smeghead
Local time
Today, 03:26
Joined
Jan 12, 2001
Messages
32,059
First, you will need Word installed on the computer you will be using this on. If it is installed and it shows a missing reference, you can either uncheck the reference marked MISSING, close the database and then reopen it. If you have the same version of Word installed, it should find it automatically and adjust the references for you.

If it doesn't, then you can manually select the correct reference by opening the Tools / References window from the VBE window and then scroll down the list until you find Microsoft Word {version number listed next} Object Library and check the box, close the window and you should be good to go.
 

Users who are viewing this thread

Top Bottom