Jumping to a section in an MS Word document - vba

I've just input a form button on my Excel sheet that the users can press to get more information on how parts of my code run. I'm planning on writing a big Word document that explains the different parts of the code in different sections. I'm looking to have a button that the user can click on in Excel for each part of the code, and that will direct them to the specific section within the Word document that I'd like to link.
So I can open a specific Word document with VBA no problems, but I'm unsure how/if I can jump to sections within the Word document.

If you use Hyperlinks instead of buttons, you can jump directly to bookmarks in your Word document, no VBA needed.
E.g. create a bookmark "Section5" in your Word document.
Then create a hyperlink in an Excel cell, with this target:
file://your_path\your_document.docx#Section5

Related

VBA - Apply document formatting to open Word doc

I am using data in an Excel workbook to create an HTML string when a user clicks a button. I then use VBA to save that string as an .html file, open it in Word, and bring Word to the foreground. That all works great.
Now, I'd like to add a line(s) to the VBA to select the document formatting.
In the Word doc that opens, there's this in the ribbon:
When I hover over that formatting option, it's called "Lines (simple)." I can click it in Word, and it formats the text exactly how I want it. But, I'd like to do so automatically with the VBA over in Excel that created and launched the Word document. Unfortunately I just don't know which command or property that is and haven't been able to find it with searches or document inspection. I'd appreciate your help.

VB code to place specific page of Visio document into Word

I've been working on a Word macro that includes a step allowing the user to select and insert a Visio file into the active Word document. Since many of the source Visio files are multipaged, and the specific Visio drawing to place in Word could be on any page of the Visio document, I need a way to allow the user to select the page they want to place.
Currently, my VBA code uses Appplication.FileDialog(msoFileDialogFilePicker) to set a variable for the Visio drawing's filepath (myVisioPath), then creates a variable for the Visio file and inserts it it into the Word doc as follows:
Dim myViz As InlineShape
Set myViz = ActiveDocument.InlineShapes.AddOLEObject(ClassType:="Visio.Drawing.15", FileName:=myVisioPath, LinkToFile:=False, DisplayAsIcon:=False, Range:=Selection.Range)
myViz.Select `Selects the Visio for subsequent actions`
The current working version of the macro selects whatever is on page 1 of the selected Visio file. I need a way to allow the user to select page 2, or page 3, or whatever page the target drawing is on in the Visio file. Currently, I'm thinking of creating a userform to allow choosing a page number, but I'm open to suggestions.
The post by Mathieu Guindon led me to the answer (would have voted it as the answer but that doesn't appear to be an option). Anyway, the code posted at Choose active page in Visio provided the basis of my solution. Set a variable for the Visio.Application object and refer to it to get both the page count of the user-selected Visio file (for error trapping if the user selects a page number that isn't available in the file) and to copy the user-selected page.

Word 2010 - Force Formatting In Specific Parts of Document

I am working with Microsoft Word 2010. I have a document that serves as a template for multiple users for a project I am working on. There are two parts of the document I want to force formatting when a user types:
Enter in an email address - I want the address to not automatically turn to a hyperlink. I want it to not turn to a hyperlink on just this part of the document. The rest of it I want hyperlinks to be enabled.
Enter in a URL without www in front (i.e. google.com), and not have the first letter automatically capitalize. I don't want to turn off capitalizing the first letter of a sentence in the whole document. Just in this part of the document.
Is this something that can be done? I tried messing with Fields but did not have any luck. I am familiar with VBA so if there is a way to do this with code, I am open to that too.
Both features you requires are implemented in Word using AutoCorrect/AutoFormat. They are not controlled by the style mechanism and consequently can't be selectively activated.
The mail address formatting can be controlled by styles, and you could prevent the switch to the Hyperlink style from being visible. You could also consider a macro that selectively changes the styles of the text as required in a post-processing pass through the documents - perhaps the next time the document is opened by a user for review.

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 copy picture from Word to Powerpoint programmatically?

I am creating a macro that converts a Word 2007 document into a structured PowerPoint 2007 presentation. I am looping over all the paragraphs of the document and copying them over to the new presentation.
I am able to copy and paste the paragraphs to the presentation just fine. But I also need to be able to copy and paste the pictures from the Word document into the PowerPoint (and in the right location between paragraphs).
So far, I am able to detect if a paragraph is a picture by looking at the paragraph's style attribute - it will say "Figure". But, I don't know what to do from there. After looking online, it looks like I should be able to do this:
paragraphFromDocument.Range.Copy
currentSlide.Shapes.Paste
But, this doesn't seem to work. How do I copy a picture from Word to PowerPoint?
Thanks
EDIT
I've also tried:
paragraphFromDocument.Range.CopyAsPicture
currentSlide.Shapes.PasteSpecial(ppPasteMetafilePicture)
and get this error message:
Shapes.PasteSpecial : Invalid Request. Clipboard is empty or contains data which may not be posted here.
But, when I use that CopyAsPicture command, I am able to open up PowerPoint (with the picture still on the clipboard from the macro) and use the Paste Special command to paste the picture to the slide.
paragraphFromDocument.Range.Copy
currentSlide.Shapes.Paste
actually did end up working, but I had to remove all special characters from the range first. That is why it was giving me the error message.