1

I want to set the name of the text box so it can be easily accessed by code. e.g

I am looking for an editing field similar to this

Thanks

bonCodigo
  • 14,268
  • 1
  • 48
  • 91
S.aad
  • 518
  • 1
  • 5
  • 22
  • `1.` How do you `add` or `define` the textbox? As a shape and then `addTextBox` or any other way? `2.` What version of Office are you using? e.g. 2010, 2013, 2003... `3`. Where's your current VBA code? – bonCodigo Jul 02 '15 at 07:28
  • **1.** I am using the ribbon. **2.** MS 2010 **3.** Its in the file – S.aad Jul 02 '15 at 07:37
  • I do not understand your question let me try to explain my question again. Is there a way to set the name of the [text box](http://my.jetscreenshot.com/24060/20150702-agw1-89kb.jpg) in publisher in a similar way like we can set the name of range in excel just by typing [here](http://my.jetscreenshot.com/24060/20150702-empe-124kb.jpg) – S.aad Jul 02 '15 at 07:56
  • After i set the name than i will access it using vba. – S.aad Jul 02 '15 at 07:59

2 Answers2

0

There's a properties Window that can be accessed for each of the controls on the UI. There you may rename the controls. (Since you do not seem to have a VBA code yet and you want to rename the control from UI)

The other alternative. Record a macro, do some changes to the textbox (e.g. resize, change text etc). Then check the programme assigned default name of the textbox from the VBA editor. As you said, you can access the control via this default name and utilizing your VBA code (as you said), rename the textbox.

bonCodigo
  • 14,268
  • 1
  • 48
  • 91
  • That is the problem i cannot find that property window – S.aad Jul 02 '15 at 08:05
  • The issue is there's no direct way to access properties in MS Publisher like how it's done in Excel, Access. No macro recorder either. So you may try to use the MS Word Macro recorder and see how it goes. – bonCodigo Jul 02 '15 at 08:50
  • I used the immediate window `? thisdocument.Selection.ShapeRange(1).Name` but now i am stuck with a worksheet object in publisher. How can i edit it via VBA. – S.aad Jul 04 '15 at 06:14
  • isn't `thisdocument` refers to the current document in publisher? Reference it in a module or publisher document in the VBA Editor like how you would do for a worksheet or a module in Excel. You started the post saying that your intention is to write a VBA code. But do you know how to code in VBA? – bonCodigo Jul 04 '15 at 14:55
0

If you really want to be editing a worksheet object in Publisher you will have to get the OLEobject of the Shape and interpret it as an Excel.Application.

If you are just looking for a placeholder solution for Publisher documents, you could simply create a textbox that contains a certain string, then loop through all pages, all shapes on each page where HasTextFrame = msoTrue, and compare shape.TextFrame.TextRange.Text to your placeholder string. If it's the one you're after, you can do anything you want with the shape in question.

Sorry for the vague answer, but your images don't work anymore.

Edit: you can work with Shape.Name for your comparison (you mentioned this property in a comment), but I have no idea how you'd set the value from the interface, without using VBA, in the first place, so if you're making templates the approach I outlined above might be easier for users (see https://msdn.microsoft.com/EN-US/library/office/ff939233.aspx for Shape.Name). There is also a .Name property for page objects (https://msdn.microsoft.com/EN-US/library/office/ff940382.aspx), so you should be able to do something like ActiveDocument.Pages("page_name").Shapes("shape_name").TextRange.Text = "your content" once you've figured out how to actually set the name values

Edit 2: You can also try to use search and replace as per Replacing Text in Microsoft Publisher Using Powershell if you don't need to do anything advanced beyond placing some text

Edit 3: Given the title of your question, unless you can figure something out with Publisher's interface, you can set the .Name property of the selected text box (or other shape) with dim shape = Selection.ShapeRange.TextFrame.Parent and shape.Name = "your_name". You can set the name of the selected page with ActiveDocument.ActiveView.ActivePage.Name="your_name". (Create a VBA macro that prompts you for names and you should be good to go)

Community
  • 1
  • 1
Jbjstam
  • 874
  • 6
  • 13