VBA - Word Table : default value and combo box - vba

I have Word Tables, and I don't find how to affect default values for certain columns...
When inserting a new line, I would like a certain column to have a certain drop-down list without user having to do it himself.
To illustrate my thoughts, here is a small image of what I'm looking for
I really don't find how to manipulate my table for it to ends up like this, so I would like to request your help.
When looking on the web for this, I only find information about table default style and no default Value.
So I would like to ask. Is this possible? If yes, how to do it?
I am looking for either a VBA code to set my column default value (which would be great), or even a way to do it in Word GUI at first. Or, obviously, an answer that would tell me that it is impossible to do in Word.
PS: the extremely easy equivalent in Excel of what i'm looking for:
Thanks in advance!

In the GUI:
Click the cell where you would like your dropdown.
In menu, switch to "Developer Tools"
Insert a Dropdown control ("Controls" are, the one in the middle)
In the ribbon, click "Design mode" (I have German Word so the actual name might differ), "Properties"
Now you can enter your options
Alternatively via VBA, I got this with the macro recorder; should give you a start:
[Cell].Range.ContentControls.Add (wdContentControlComboBox)
ActiveDocument.ToggleFormsDesign
Selection.ParentContentControl.DropdownListEntries.Clear
Selection.ParentContentControl.DropdownListEntries.Add Text:="Yes", Value _
:="Yes"
Selection.ParentContentControl.DropdownListEntries.Add Text:="No", Value:= _
"No"

Related

How can I change Access hyperlinks with VBA?

I've done some extensive research and realize this is not an easy task.
I need to change many hyperlinks in different tables from P:\Library\Folder... to I:\Folder...
I think I can change the field type to long text, find and replace, change type back to hyperlink.
Table Find/Replace dialog will work on Hyperlink field if there is no DisplayText component in hyperlink string.
In either case, an SQL UPDATE action will work, like:
CurrentDb.Execute "UPDATE table SET field = Replace([field], 'P:\Library\', 'I:\')"
It is possible to have hyperlink functionality on form and report in ReportView without Hyperlink type field. Of course this will require alternate method than hyperlink field interface to enter file path into text field - probably with VBA executing File System Object dialog. Hyperlink click will not be possible in table but since users should not interact with tables and queries, just forms and reports, this should not be an issue.

How can I build custom Word fields with VBA

I've found a question in stackoverflow: "How can I build Word fields with VBA" by JonnyGold.
I'm interested in the same question, but possibly on other reasons. The answers to JonnyGold question doesn't satisfy me. I'm still in MS-word 2003. My problem is to construct a custom word field, which would recognize a bookmark name around cursor location, saves that name in some custom variable/property, so that in a case of need a hyperlink of ref field could return a cursor to the said bookmark.
I need that mechanism to facilitate an easy work with a list of bibliographic sources, so that a user can by one click to go from a reference to a source and then to return back. Note that one source could be referenced in several different places and a user should be able to return to a reference, he/she clicked before.
I tried to use REF field with MACROBUTTON field inside, but MACROBUTTON requires double or one click on a button/text, which I want to avoid. I would like to create a field {RUNMACRO MacroName}, which would run a specified VDA Macro.

How do you change a name mentioned multiple times in a region

I wanted to know if there's shortcut to change a name like "tom" to "sally" in a region in Visual Studio 2013. I have about 40+ tom's and to change it manually takes forever. I'm using vb.net. Any help is much appreciated.
Other than using a find and replace (CTRL+H), you can use a text editor like sublime text:
https://www.sublimetext.com/
You can limit the replacement to a selected region of text. In the Find/Replace dialog there is a "Look In" drop down. If you have text selected, you will have the option "Selection" It's only visible when you have selected text which is confusing/misleading (why not just disable?).
You can then use replace all, and the replacement will be limited to the selection region.
If you collapse a code region you can select the entire region easily.

Catia v5 VBA, StartCommand "Constraint" doesn't give the expected result

I'm trying to create a toolbar in Catia. This toolbar (based on a VBA form) will have buttons which should start Catia Commands (among other things). One of the commands I'm trying to start is the "Constraint" command (which should allow you to place dimension to sketch elements in the Sketcher Workbench).
I looked in the command list (view->commands list...) and found "Constraint" for the dimensioning tool and "Constraint..." for the "Constraint box" (which opens a box where you can set geometrical constraints, which is not what I want). I tried with this (the simplest case):
Sub CATMain()
CATIA.StartCommand ("Constraint")
End Sub
and I also tried writing "c:Constraint" in Catia's command field at the bottom of the window.
None of these attempts give me the Constraint command I'm looking for. Instead I get "Unavailable Command" but if I select the sketch element I want to constrain I get the "Constraint box".
How do I start the "Constraint" command (used for dimensions) from VBA instead of the "Constraint Box"?
Regards,
Christian
EDIT: Fixed some minor spelling mistakes
Be careful that starting commands by name is locale-dependant. It means you should type "Constraint" in an english CATIA, "Contrainte" in french, etc...
Here is a good article on StartCommand, giving a few ways to find command names : http://v5vb.wordpress.com/2010/01/20/startcommand/
By the way, I tried both english and french and on my CATIA R20, it actually launches the command (waiting to select an element to constraint.)
Be careful to be :
in sketcher
with no other command running
If you only want to get the constraint command available all the time, just do a shortcut for it.
Open Sketch->Right Click on any bar -> Customize -> Commands Tab -> Select the command -> Show Properties -> Assign Shortcut.
Example, assign F6 to "Constraint" and that would be equal to:
Sub CATMain()
CATIA.StartCommand ("Constraint")
End Sub
If you want actually constraint two geometrical elements through vba, this is other matter. Say if you need more info on this.
your question is quite unclear, what do you want to achieve in fact with constraints? additionally "Constraint" function doesn't have any dialog attached to it, but "Constraints defined in dialog box" does, in order to make any of them to do any action, you have to pre-select some geometry on which is possible to make such constraint first
you dont need to customize anything, those functions by default have icons defined so you can always use them with start command, if you are in correct workbench of course, as constraint function exists on different levels, part, product, sketch..

Using VBA in MS Word 2007 to define page elements?

I'd like to be able to create a page element which I can feed text and it will form itself into the preferred layout. For instance:
{MACRO DocumentIntro("Introduction to Business Studies", "FP015", "Teachers' Guide")}
with that as a field, the output should be a line, the first two strings a certain size and font, centred, another line and then the third string fonted, sized and centred.
I know that's sort of TeX-like and perhaps beyond the scope of VBA, but if anyone's got any idea how it might be possible, please tell!
EDIT:
Ok, if I put the required information into Keyword, as part of the document properties, with some kind of unique separator, then that gets that info in, and the info will be unique to each document. Next one puts a bookmark where the stuff is going to be displayed. Then one creates an AutoOpen macro that goes to that bookmark, pulls the relevants out of the keywords, and forms the text appropriately into the bookmark's .Selection.
Is that feasible?
You're certainly on the right track here for a coding solution. However, there is a simpler way with no code - this is the type of scenario that Content Controls in Word 2007 were built for and with Fields/Properties, you can bind to content controls (CC). These CC can hold styles (like centered, bold, etc.). No VBA required.
The very easiest thing to do is to pick 3 built-in document properties that you will always want these to be. For example, "Title" could be your first string, "Subject" your second string and "Keywords" your third. Then, just go to the Insert ribbon, Quick Parts, Document Properties and insert, place and format those how you like. Then go to Word's start button (the orb thingy) and then under Prepare choose Properties. Here you can type, for example "Introduction to Business Studies", into the Title box and then just deselect it somehow (like click in another box). The Content Control for Title will be filled in automatically with your text.
If you want to use this for multiple files, just create this file as a .dotx (after CC insertion/placement/formatting and before updating the Document Properties' text). Then every time all you'll have to do is set these three properties with each new file.
Well, yes, it did turn out to be feasible.
Sub autoopen()
Dim sKeywords As String
sKeywords = ActiveDocument.BuiltInDocumentProperties(4)
ActiveDocument.Bookmarks("foo").Select
Selection.Text = sKeywords
End Sub
Okay, I have some filling out to do, but at least the guts of it are there.