Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Extracting pages from Adobe to Word

Status
Not open for further replies.

James_Martin001

Programmer
Apr 6, 2022
1
0
0
GB
thread707-1807215
I have a work stream where a Macro Es saves a customer Outlook email to docx and leaves open and saved. I have a Macro A to save all attachments to a C Drive folder. And in Word a Macro I to insert the images only to the cursor point in Macro Es docx. I use a page/section/header&footer unlink Macro which I call Macro B (amazing for 1 click on QAT). The Macro A kills the previous files on each QAT press. I have a Macro RS with the help of UserForm to rotate all or a selection of images by 90, 180,or 270 degrees. Macro s is added to Macro Es to force high Res embedded images from customer mobiles or tablets, to within the margins of the docx. I had to create an inverse of this Macro S to maximise the images as when moving them in the docx, or rotating from the original orientation in landscape, they keep the justified A4 width for the document height, so automatically the corrected landscape fills the A4 to 660 pixels, in portrait.

So far so good.

I have only been able to create Macro P recently to instantly convert any Macro A doc/docx/rtf/odt to pdf. Along with other customer Macro A original pdfs, if the collective page totals are about 8 pages I manually open all the pdfs by selecting with the mouse and right click open. For each I rotate to landscape, full screen,PrtSc,START,select Macro Es on Taskbar, Ctrl+v, START,select Acrobat Reader on Taskbar, and repeat until finished. The idea is to reduce drastically the files my colleagues have to review on a customer system, and to automate the process for speed. We can only upload files max to 4 MB. I have to select an image and via Picture Format and then Compress Pictures, apply 150ppi initially, sometimes going down to 96ppi is OK. I have given up trying to do a Macro C to automate this, struggled with SendKeys...

I had given up on doing a pdf macro to automate the pdf insertion to Macro Es docx as don't have Adobe Pro at work. But found this macro, that made me realise it might be possible:
I took out "ThisWorkbook.Path" at the beginning, and added a test pdf path and file name in the speech morks after the "OpenPDF", first active VBA in the sub.

For the note above the block "Get the PDF file name from the full path"
I had to replace with
"strPDFName = Mid(StrPDFPath, 61, 255)
To force the file name, the path is a bit long where the pdf is saved.

The enabled line for Word App opens the test 10 pages pdf, and brings to the foregroundWindow via an assigned value for "1Parent".

Then the macro bypasses the blocks to do the pdf page selection and then the page zoom change, as the "1FirstChildWindow" etc, do not get a value asigned, when the Locals Window is open and going through with F8. Not sure what to amend to get the page number and zoom to work. If I can get this to work, I might be able to sort out the automation for my work stream for the pdfs. Any help would be appreciated.



The macros above have doubled output and standardised the email file name, I have also put error handlers to omit email signatures and banners from being uploaded by Macro I, this basically uploads all images but each loop ends with a delete out images if below 180 pixels.

The final Macro to mention is Macro X, an afterthought really but it replaces Word, File, Close. This does not sound significant, but if it saves 10 seconds each time and I use it 53 times it saves 2% of work time each day. It helps the flow of work via the QAT. It works if the doc in the active window is in protected view or not, And does nothing if pressed in error with no document in the active window. You can do this in other Office 365 Apps. I use the X for the QAT above the Ribbon.

Sub WordFileClose()
'Macro X
'SOURCE: jam61mar@gmail.com


Application.ScreenUpdating = False

Dim WrdPV As ProtectedViewWindow

'If a file is Protected View, Make it Editable

If Application.ProtectedViewWindows.Count > 0 Then

'if protected view file is not active window

On Error GoTo Stage2

ActiveProtectedViewWindow.Edit

End If


Stage2:


'If Macro X is pressed in error with no file in Open Word App

On Error GoTo Terminate

'if Active window has a document close it

Application.activedocument.Close

Exit Sub

Terminate:

Application.ScreenUpdating = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top