My goal is to call a macro (with input of specific information from the shape) inside a shape in the MS VISIO application.
The macro is to open a PDF datasheet of the specific shapes (the element in my block diagram).
I have an idea to trigger the macro from the specific shape, which is inserting action section and using runaddon function to run the subprocedure (using shell to open a specific PDF file).
Question:
How do I pass an argument (type of string) of the shape (in my case it is a PDF file name for this shape) to the subprocedure? If that can be achieved, I can open each shape's corresponding datasheet.
How do I save the input argument value (type string) inside each shape?
And how do I call them inside VBA subprocedure?
Visio has hyperlinks. You can just add a hyperlink to your shape pointing to your PDF, and the menu item action as well as click behavior will be added automatically.
So, click Ctrl+K to add a hyperlink, or use "insert" menu.
You can also add hyperlink programmatically, or by linking to a data source (like excel). Also you can build URL of the link as a formula, out of shape data, like shape text.
If you still want to do it with vba macro, you can try CALLTHIS function: https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa212649(v=office.11)?redirectedfrom=MSDN#example-1
Related
I want code a search function via VBA that searches for a specific text and highlights the first result in PowerPoint (like the normal search window, that can be opened with Ctrl + F).
I want to code this in VBA, because I want to search for multiple texts (I have a sub, where I deliver the search text as parameter) and do not want to have to type the search texts manually in the search window.
Having a sub with a parameter is not the problem.
The problem is highlighting the first result.
I found this code here (the first answer in this topic):
powerpoint search box vba
The only thing that I need is to switch to the slide and highlight the text.
I want to add a chart inside a textbox using VBA in Microsoft word.
I have tried using
ActiveDocument.InlineShapes.AddChart()
API;
with cursor inside the textbox and still it doesn't produce the desired result
Unless you specify where the chart is to be placed it will simply be added to the document. If you had looked at the help text, IntelliSense or the Object Browser you would have seen that the method takes a Range as an argument. To place the chart in a specific location the range is required.
For example:
Set shp = ActiveDocument.InlineShapes.AddChart(Range:=Selection.Range)
I'm trying to write a PowerPoint VBA macro that would act differently whether a shape is merely selected or is in edit mode (i.e. the cursor to edit the text is present, see image).
Is there a way to check this using VBA in PowerPoint? I haven't been able to find on this anything so far
My ultimate goal being:
If just the shape is selected, the macro will align the shape left
If the shape is in edit mode, the macro will align the text left (and leave the shape where it is)
Any help would be appreciated
Best
You can do this by using Selection.Type. If it returns 2, the shape is selected. If the insertion point is in the text, it will return 3:
Sub DetectShapeOrText()
MsgBox ActiveWindow.Selection.Type
End Sub
PpSelectionType enumeration (PowerPoint)
I'm trying to grab the text from inside a shape on a Word document.
Sub textgrab()
MsgBox ActiveDocument.Shapes("Rectangle 85").TextFrame.TextRange.Text
End Sub
I get the error:
Run-time error '-2147024809 (80070057)':
The item with the specified name wasn't found.
In the Word document when I go to the top menu, hit the shape format tab, and in the arrange section, I select 'selection pane', I get a list of all the shapes, 'Rectangle 85' is there.
When I select it, it highlights the box i'm trying to grab the value from.
This is a pdf that I've opened in Word. I'm trying to automate a process that will open a pdf invoice, grab the dollar total, and pull it into Excel.
Solution for those that stumble upon this later. I used the following:
ActiveDocument.ActiveWindow.Panes(1).Pages(1).Rectangles.Item(i).Range
Word can only extract text from Drawing objects. These are inserted in the UI, for example, from Insert/Shapes. Shape.TextFrame.TextRange has no OCR capabilities, so can't be used to get text "embedded" in other kinds of graphic objects, such as an embedded PDF file or a JPG or anything similar.
When uncertain whether a particular Shape supports reading or writing text, right-click it in the UI and see if the menu selection Add Text or Edit Text is available.
Is there a reason why my MS Word VBA macro is ignoring a dropdown list I placed inside a shape (a rich text box)? I've tried referring to it by tag, name, number, etc. I even had the macro tell me the count of content controls:
MsgBox(ActiveDocument.ContentControls.Count)
I get 0.
Nothing works. If I take it out of the shape, it works fine. MS Word gives me a count of 1 item. But for some reason MS Word won't acknowledge it inside the shape. Any help on how to do this?
Edited as my previous post was completely wrong.
Each textbox in the main text story is a Shape which you can access using an index number. A shape has various properties but text etc. is in its Textframe, if it has one. But in that case the Range you need is not called Range but TextRange. So, e.g. the first contentControl in Shape 2 is
ActiveDocument.Shapes(2).TextFrame.TextRange.ContentControls(1)
You will probably need to iterate through your shapes and you may need to verify that a given shape is a textbox and/or that it has a TextFrame.
If your text box is in another Story such as a header or footer, you will probably need to identify the relevant StoryRange.