How To Save a PPTX File with VBA - vba

So I'm making a powerpoint game, and I want there to be a save feature. I remember seeing a save function while browsing through the commands but I don't remember what to do. Does anyone know how to save a powerpoint file with a simple line of code? it can't be that complicated.

You want the Save method of the presentation object:
Application.ActivePresentation.Save
You can find methods using the search box in the Object Browser:

Related

Visio macro to save a macro-free file

I have a series of complex charts to draw, so I have written a macro that takes a set of instructions from a CSV file and draws them appropriately. This works, but I need to manually save the produced page as a .vsdx file (i.e. without my macro code) after the fact.
What I'd like to do is specify the filename in the input file and have it produce a macro-free visio file of that name.
I've tried
Application.ActiveDocument.SaveAs filename
but this immediately generates a run-time error: "VB projects cannot be saved in macro-free files".
I understand that - I don't want my macro code in each of the (dozens of) flow charts I'm drawing. How can I suppress this error?
Thanks in advance.
If you want to have your macro(s) stored in a document file, then you'd want to have your macro generate a new document in which you draw your complex charts. But as #y4cine commented, you need to keep your code separate from your content, if you want to save your content as macro-free files.
Otherwise you may be able to set Application.AlertResponse to whatever response Visio asks interactively when you try to save a file that has a macro as a macro-free format.

VBA code in a template

In a Word template I have a command button with VBA code behind it.
The problem is that the code gets lost when a document is created using that template. The button is still visible, but the VBA code behind it disappears for some reason. This causes the button just to be clickable without performing any action.
The documents are saved in .docx format.
How can I 'glue' the button to its code so it doesn't get lost ?
First, make sure your VBA code is saved in the .dotm template that you make available to everyone (and not in your personal normal.dot/dotm template — this is only available on your machine).
Then, make sure the documents generated from the template are saved as .docm (not .docx).
.docx documents cannot contain VBA code. Anything saved in .dotx or .docx format will, by definition, lose all VBA code.
In a comment you say
"this doenst matter, as the document is just used for the macro."
This is incorrect; it does very much matter. .docx documents can't "be used for" macros because they can't contain macros.
For the macro to be always available, you need to store the macro in the normal template.
For example when recording a macro, select All Documents (Normal.dot) on Store Macro in.

How can I embed a PDF in a Word Doc, and access that PDF with VBA?

I have a word doc with some ActiveX buttons on it. When one of these buttons is pressed, a UserForm pops up with a corresponding PDF displayed, like so:
This is exactly the behavior I want. However, the problem is that for this to work, the user of the word doc needs to have each of the PDFs saved on their machine as well. Here's the code for one of the buttons:
Private Sub AC1Button_Click()
DisplayForm.AcroPDF1.LoadFile ("C:\Users\arose\Desktop\Security Control Doc\Sub PDFs\AC1.pdf")
DisplayForm.Show
End Sub
As you can see, the path is hardcoded in. I need to be able to distribute this word doc without needing to distribute a bunch of PDFs along with it, so is there any way to embed PDFs in a word document in such a way that they're accessible by VBA?
I've discovered here that it's reasonably easy to embed a PDF in any office doc. And I've tried that:
But I can't figure out how to access that PDF object in my VBA code, in order to display it on the UserForm.
Any insight is appreciated, thanks!
Embed the files (and display as icon to stop them taking over your document)
To activate the first OLE object in your document,
ThisDocument.InlineShapes(1).OLEFormat.Activate
is the command.

How to save options of a VSTO add-in in the currently open file?

I'm building a VSTO add-in for Powerpoint 2010 and the options the add-in sets apply to the currently open file instead of a per-user config. Can I save these options in the current file (I mean, add custom XML to the .PPTX file)? If so, how?
Thanks for your help.
For very simple data, custom properties are ok (so long as you're aware that anyone who opens the file will be able to see, edit and delete them). And note that because PPT shares a common, too-small, allocation of data between links and document properties, adding too many of one can wipe out the other.
I'd use tags instead. Every shape, slide and presentation object can have a tags collection, containing one or more Name / Value pairs of strings.
These are invisible to the user and will not interfere with the hyperlinks in the presentation.
' To add a tag
With ActivePresentation
.Tags.Add "MyTagName", "MyTagValue"
End With
' To use a tag
If ActivePresentation.Tags("MyTagName") = "MyTagValue" Then
' Do something or other
End If
If your Options are not too complex, I would go for Document Custom Properties. The following question illustrates how to use Custom Properties with Excel, they are supported in PowerPoint as well so this should provide a good starting point!

Indesign scripting - Save Copy

I'm using a Objective-C Scripting Bridge to communicate with InDesign CS3/CS4. Unfortunately I'm stuck on Save command which appears to be existing only as a part of the standard suite and not defined again in InDesign. Because of that it looks like I can Save, Save as but not Save Copy a document. Does anyone have any idea how to proceed?
Just to shortly explain the difference between Save and Save Copy - using Save Copy the current doc doesn't change which is opposite to Save or Save as.
the only other alternative other than that which philip-regan suggests. Would be to use GUI scripting but I'm still not sure what the point would be. If you wanted to save time of not closing and reopening you could save the doc make a duplicate via the finder and continue onward in indesgn with out the close and re-open bit
I always thought the distinction between Save As and Save Copy as being more semantic than anything because all that command is really doing is performing a Save As but appending the file name with " copy" (e.g., "MyLayout.indd" becomes "MyLayout copy.indd"). Just use Save as a Save Copy alternative by giving an alternate name for the document when you save it.
Edit per OP's comments: You're right that Save Copy isn't defined in the dictionary. The only way I see around this is to mimic the command's behavior by saving to a location with a new name, closing the current-yet-renamed document, and reopening the original. Not ideal, I know, but I don't see another way around it, unless Save Copy is defined in the Javascript API, which I doubt.
Well,
since Save Copy is not defined in the scripting dictionary, the only way how to proceed is to save current document a create a copy via Finder.
If you search the header file for InDesign, these are the methods that pop up:
- (InDesignDocument *) saveTo:(id)to stationery:(BOOL)stationery versionComments:(NSString *)versionComments forceSave:(BOOL)forceSave; // Save the document
- (void) saveACopyTo:(id)to stationery:(BOOL)stationery; // Saves a copy of the document.