PDA

View Full Version : [SOLVED:] Multiple pages to image



Dave
03-06-2018, 09:40 AM
I'm trying to convert a multipage document to a single image. Using some API code, the document contents are copied and the image is placed in a frame control on a userform for viewing. Everything works well for 1 page but not for more than 1 page. The picture "ends" at the end of page 1. Similar to manually copying multipages, opening a new document and pasting as picture... the image is cropped at the end of page 1 even though the entire multipage document is available (which can be seen by pasting as text). Anyways, my question would be, is there any VBA way to include all of the document pages in 1 image? Dave
ps. I should mention that I'm using XL VBA to attempt to achieve this. Also, that this would not be needed if either there was a way to manually close a document while maintaining the Word application OR the Word 2016 application didn't take so long to load/unload. In previous office versions, I never had this difficulty.... grrr

macropod
03-06-2018, 02:15 PM
I'm trying to convert a multipage document to a single image. Using some API code, the document contents are copied and the image is placed in a frame control on a userform for viewing. Everything works well for 1 page but not for more than 1 page. The picture "ends" at the end of page 1. Similar to manually copying multipages, opening a new document and pasting as picture... the image is cropped at the end of page 1 even though the entire multipage document is available (which can be seen by pasting as text).
What you get very much depends on the code you're using, which we haven't seen. That said, anything that uses a page metaphor for its image production is limited to what fits on a single page; what you can copy as text is quite irrelevant.


this would not be needed if either there was a way to manually close a document while maintaining the Word application OR the Word 2016 application didn't take so long to load/unload.
You can close all Word documents without closing Word. Simply uncheck the 'Show all windows in the taskbar' option...

As for the time it takes to load Word, if you're doing this through code, use early binding and declare your Word objects accordingly.

Dave
03-07-2018, 07:18 PM
Thanks Paul for your reply and your confirmation that it's impossible to have a multipage image. I have a couple of days of code that confirms this, that didn't work, that I could have posted :)

Simply uncheck the 'Show all windows in the taskbar' option got me excited. Something like...

With Application
.ShowWindowsInTaskbar = Not .ShowWindowsInTaskbar
End With
...doesn't work for Office '97-2003 which is apparently required for use with .doc files accessed by Word 2016. I do not want to set a reference so I am using late binding. General operation of my objective has several option buttons on an XL userform that when selected, open a specified Word document. Using all Office versions since '97, this has always been quick (2 or 3 secs). Office 2016 is taking 10 to 15 seconds. Most of this time is taken to start the Word application. To avoid this delay is my ultimate goal. Toward this end, not closing the Word application on document close would be best. Having the Word application open before option button selection is second best which is what the following code does. The code opens the Word application before userform.show, re-opens Word after document close (manual) then quits Word following userform.unload.
XL module code...

Public PFWdApp As Object

Public Sub NofileEr1()
'Open Word application before Userform.Show
On Error Resume Next
Set PFWdApp = GetObject(, "Word.application")
If Err.Number <> 0 Then
On Error GoTo 0
Set PFWdApp = CreateObject("Word.Application")
End If
PFWdApp.DisplayAlerts = False
End Sub


Public Sub CheckWordApp()
're-open Word application after document close
On Error Resume Next
Set PFWdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
On Error GoTo 0
Set PFWdApp = CreateObject("Word.Application")
Exit Sub
End If
Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), Procedure:="CheckWordApp"
End Sub

Public Sub NofileEr2()
'Close Word application after Unload.Userform
On Error Resume Next
Set PFWdApp = GetObject(, "Word.application")
If Err.Number = 0 Then
PFWdApp.DisplayAlerts = True
With PFWdApp
.Application.Quit
End With
End If
On Error GoTo 0
Set PFWdApp = Nothing
End Sub


To operate (userform code)...

Sub test()
'Open Document. Re-open Word open after document close.
PFWdApp.Visible = True
PFWdApp.Documents.Open Filename:="Full file path", ReadOnly:=False
Call CheckWordApp
End Sub
Again, thanks for your assistance. Any further information or suggestions welcome. Dave

macropod
03-07-2018, 09:50 PM
Office '97-2003 which is apparently required for use with .doc files accessed by Word 2016.
I don't know where you got that idea from - Office 2016 can open such files.


I do not want to set a reference so I am using late binding
.
If that's because you want to support earlier versions of Office, simply use early binding and compile the code on a system using the earliest version you want to support.

If you need you code to work with older Word versions (irrespective of whether you use early or late binding), you could test the Version #. For example:

If Int(Application.Version) > 9 Then Application.ShowWindowsInTaskbar = False

Dave
03-08-2018, 10:32 AM
Thanks again Paul for your time. A bit of misstatement/misunderstanding... I meant that Application.ShowWindowsInTaskbar doesn't appear to do anything for 97-03 .doc(s) when using Word 2016. My understanding of references is that if the .doc is saved in a newer version of Office the reference is updated. An error problem occurs when that .doc is then accessed by an earlier Office version...a possible scenario that I want to avoid. I'm going to trial early binding just to see if it makes a difference. I'll post with the outcome or if I happen upon a different resolution. Dave

macropod
03-08-2018, 01:43 PM
My understanding of references is that if the .doc is saved in a newer version of Office the reference is updated.
That will only happen if you recompile the code in the later version. Simply resaving the document or template containing it has no effect.