I'm creating the program for exporting several excel sheets to pdf with watermarks and form fields etc. Everything works smooth right now but the final pdf is quite large. So I was thinking about the best way to make it smaller and I found out that the best result is by simply opening the pdf in Adobe Acrobat and then print it with "Adobe PDF" printer. This way I reduce the file size to 1/6 of the original size.
So I'm trying to do this via the VBA code and it looks like it's prety straight forward code using the JS.
sPath = "some path"
sPathFinal = "some other path"
Dim AcroApp As AcroAVDoc: Set AcroApp = CreateObject("AcroExch.AVDoc")
Dim Document As AcroPDDoc
Dim JSO, pp
AcroApp.Open sPath, ""
Set Document = AcroApp.GetPDDoc()
Set JSO = Document.GetJSObject
Set pp = JSO.getPrintParams
pp.printerName = "Adobe PDF"
pp.Filename = sPathFinal
JSO.Print (pp)
The problem is in the very last line as it should be
JSO.print(pp) - "print" with lowercase "p"
But everytime I step away from the lane, it gets autocorrected to uppercase "P". I tried to turn everything off in Tools -> Options -> Editor -> Code settings as well as on other places in options tab but had no luck so far.
Is there a way to prevent this autocorrect?
(Also I'm not native english speaking so there is quite big chance that it is called differently :)
Short answare is no you can't, because VBA editor auto-correct the case in your code.
This is because VB is case-sensitive (despite it doesn't look like it is), and the editor tries to prevent typo by changing the case of your variables.
If you want to preserve the case and avoid auto-correct, the simplest solution is to use another editor (like Notepad) and compile your code from the command-line.
Hope this help.
Related
At the moment, I have a Visio file that hasa network zoning diagram (Page 1) where a user can put shaped in different zones. One can run a VB macro over that page, which will collect all kinds of data that is specific to those shapes and flows and exports it to a Word file for further reporting. That's all good and work as expected.
However, the networking zoning is different on for instance cloud. So, I want to make another page (Page 2) in the same file, that has more cloud (GCP, AWS) oriented zoning details (VPC etc.). And I want to run the same macros over that Page (2) to export the details to a word file.
PROBLEM: How and where should I tell the macro which Page it should get the data from in order to run the output. I have been playing with things like "Set vsoPage = ActiveWindow.Page" and have that executed before the macro collects all the meta information of the shapes
My hope was, based on the MS Visio page, that the macro would grab the shapes from the page that would have been active.
But no, it just spits out stuff on Page 1. And not Page 2 (although active).
Just wondering if:
- this is the right line of code to use?
- is the location correct?
Many thanks for your help
More likely to be:
Set vsoPage = ActivePage
I'm not exactly sure how and when your macro works, but here's some snippets that might help:
'// Get the active page:
Dim visPg as Visio.Page
Set visPg = Visio.ActivePage
If Not(visPg Is Nothing) Then
...
End If
'// Here we'll be really picky about the active window, this is
'// probably overkill, but Visio can have several different types
'// of active windows:
Dim visPg as Visio.Page
Dim visWin As Visio.Window
Set visWin = Visio.ActiveWindow
If (visWin .Type = Visio.VisWinTypes.visDrawing) Then
If (visWin .SubType = Visio.VisWinTypes.visPageWin) Then
'// The active window is a drawing page window, and not
'// a master-editing window, nor a group-editing window:
Set visPg = visWin.Page
'//...do stuff with visPg
End If
End If
Consider VBA for PowerPoint -
Is this a valid Presentations function call?
Presentations(".\directory\ppname.ppt")
Note that this will be called from within a PowerPoint presentation VBA, to open another one in a sub-directory.
The Microsoft Presentations examples (and most others) are not specific about the filename forms accepted, e.g. those using the ".", "..", "\" directives recognized in DOS scripts.
This seems to work with Powerpoint 2007.
As described in the comment, it takes a block of text (the TextRange), the starting position and length of file reference, also a LinkAddr. LinkAddr is essentially a DOS-style file reference, like "..\folder\ppfile.ppt".
The intention here is to launch another PowerPoint tool by invoking its show.ppt or show.ppsm file name. The file name can refer to some other directory using MSDOS file name stuff. I don't know whether it can span different machine platforms, but it seems to work within one Windows 10 system.
My difficulty in getting this to work was some full-path links to images, e.g. something like C:\blah\blah\image.jpg, in the Visual Basic code. PowerPoint didn't like these, instead asked about enabling macros, and just hung up when one of my file links were to be executed. By getting rid of the "macro" complaints, this suddenly started working.
Or maybe some bugs have been fixed in recent repairs to my 2007 PowerPoint tools??
Go figure...
Sub InsertLink(ByRef Trange As TextRange, fpos As Long, msglen As Long, LinkAddr As String)
' Insert an HTML link into the selected TextFrame.
' get the character range
Dim Hrange As TextRange
Set Hrange = Trange.Characters(Start:=fpos, length:=msglen)
' make it an HTML link
With Hrange.ActionSettings(ppMouseClick)
.Action = ppActionHyperlink
.Hyperlink.Address = LinkAddr
End With
End Sub
I've spent 2 days trying to find the solution with no luck.
I have a XPS file which I am displaying in a document viewer, and what I want to do, is use a variable that I have, to navigate to a certain place in the document within the viewer.
Firstly, how would I set some sort of identifier within the xps document? At the moment, I have got bookmarks set in it from word and then converted to xps, which I can see in the FixedDoc file, therefore I know it can see them, but I don't know how to the utilise this.
At the moment I have:
Dim _XpsPackage As XpsDocument
_XpsPackage = New XpsDocument(xpsFilename, IO.FileAccess.Read)
docViewer.Document = _XpsPackage.GetFixedDocumentSequence
Dim _CurrentDocSection() As String = Split(_CurrentWindow.Title, ".", 2)
Dim docSeq As IXpsFixedDocumentSequenceReader = _XpsPackage.FixedDocumentSequenceReader
Dim doc As IXpsFixedDocumentReader = docSeq.FixedDocuments(0)
Dim a = doc.Uri
From here, I want to use _CurrentDocSection(1), as my identifier and then navigate to where that bookmark is within the document, but cannot seem to find it.
Thanks
I want to split a multi-page MS Publisher 2010 document into a set of separate documents, one per page.
The starting document is from a mail-merge, and I am trying to produce a set of numbered and named tickets as PDFs to send to people for an event (this is for a charity). The mail-merge seems to work fine and I can save the merged document and it looks OK with e.g. a list of fifty people giving me a 50-page document.
Ideally the result would be a set of PDFs.
I have tried to create some simple VBA code to do this, but it is not working consistently. If I try this very simple macro below , I get the correct number of documents, but only perhaps 1 or 2 documents with the correct contents out of every five. Most of the documents are completely empty.
Sub splitter()
Dim i As Integer
Dim Source As Document
Dim Target As Document
Set Source = ActiveDocument
For i = 1 To Source.Pages.Count
Set Target = Documents.Add
Source.Pages(i).Shapes.Range.Copy
Target.Pages(1).Shapes.Paste
Target.SaveAs Filename:="C:\Temp\Ticket_" & i
Target.Close
Set Target = Nothing
Next i
End Sub
I did sometimes get an error that the clipboard is busy, but not always.
Another approach might be to start with the master document and do this looping over the separate documents and fill in the personal details for each person's ticket and directly produce the PDFs. But that seems more complex, and I am not a VB programmer (but been doing C++ etc for 20+ years, so I can program :-) )
A final annoyance is that it seems to keep opening a new Publisher window for each document. It takes a while to then close 50+ copies of publisher, and the laptop starts to crawl...
Please advise how best to get round these issues. I am probably missing something trivial, being a relative VB(A) newbie.
Thanks in advance for any suggestions
Try coding something like this:
Open Publisher application (CreateObject()?)
Open Publisher document (doc.Open(filename))
Store the total amount of pages in a global variable (doc.Pages.Count)
Close document (doc.Close())
Loop the following for each page
Copy the pub file and rename it to name & "page" & X
Open the new pub file
Remove all Pages except page X from the pub file
doc.Save()
doc.Close()
Copying files with VBA is easy, but copying pages in Publisher VBA is quite a hassle, so this should be easier to achieve
It has been a long time since doing any type of coding.
I've been tasked to send a test page (looks like old TV test pattern page) to all of our printers prior to shift start. These pages will help our team determine if there is any physical issues with the printers (bad toner, fuser, etc)
I have found this code and used in a VBA (MS Word).
Sub Sorterprint01()
Dim sPrinter As String
Dim sPrinter1 As String
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "\\dc999nt09\USPRT_01"
.DoNotSetAsSysDefault = True
.Execute
Application.PrintOut FileName = "\\dc999file\share\7yr\Support\IS_TEAM_LOCAL\TEST SHEETS\BARCODE TEST SORTER01.docx"
.Printer = sPrinter
.Execute
End With
End Sub
I even created a form to print to all or just a specific printer.
Management does NOT want this in a word doc and would prefer to have this in a VB app (even better would be web based).
After extensive research I have found that wdDialogFilePrintSetup is a WORD based dialog and does not work in VB6/2008/2013). I am just getting back into coding and need a quick solution.
Use Automation. If you want to print docx files then you'll need word.
Set word = CreateObject("Word.Application")
With Word.dialogs(wdDialogFilePrintSetup)
etc. Just preface your objects with word..
If using VBScript (which can't access constants - nor can VB6 if you don't add Word as a Reference) you need to specify the actual number that wdDialogFilePrintSetup is equal to.
So
With Word.dialogs(97)