![]() |
#1
|
|||
|
|||
![]()
I have a word form where I use a content control date picker for the user to enter 3 dates
I need to use the value of one of these dates to make up the filename when the document is saved. My problem is that I cannot figure out how to retrieve the value from the content control. Any help greatly recieved. The other fields are all bookmarks taken from a userform, but I couldn't find a way in the userform to allow the user to pick a date from a pop up calendar, this would be the other option to what I am trying to do. Thanks |
#2
|
|||
|
|||
![]()
If you want a date picker on a userform, first you need to get and register the file mscal.ocx. For that, visit http://www.fontstuff.com/vba/vbatut07.htm. Step 2 on that page also explains how to put the control on the toolbox and how to use it. The drawback here is that you need to have the ocx on every computer that will use the form, and it's no longer common.
If you stick with the content control, then you can get its value with the expression ActiveDocument.ContentControls(1).Range.Text -- just substitute the correct index in the parentheses to get the particular control you need. Alternatively, put a unique Tag value in that control, and use the ActiveDocument.SelectContentControlsByTag method to get the correct one. (That method returns a collection of content controls, but if your tag is unique then you know the collection contains only one control, so you can use the index 1 to get the control.) |
#3
|
|||
|
|||
![]()
Thank you very much for the help, worked great, except
The date they enter shows in the format 24/05/2012 whereas I need to use it in the file name as 'yyyy mmdd' with the space in the middle. The bit of code I have is very simple. Dim FBdate FBdate = ActiveDocument.ContentControls(3).Range.Text Do I need to specify FBdate as a date, and how do I then get the bits of it to get year, month, day or is there a function that does this. As you can probably tell I am a novice at this. Thanks |
#4
|
|||
|
|||
![]()
The simplest way to change the arrangement of the dates is to use the Format function. I'd recommend that you look up the Help topic about this function to see all the things it can do (easy: after you type Format in the macro window, put the cursor inside the word and press F1). For this specific case, what you need is
Dim FBdate As String FBdate = ActiveDocument.ContentControls(3).Range.Text FBDate = Format(FBDate, "yyyy mmdd") At that point FBDate will have the proper form, and you can use it to make a file name. If you need to do other things with the date, such as adding days or months to it, investigate the data type named Date and the function CDate that converts strings to Date objects. |
#5
|
|||
|
|||
![]()
thankyou for your help.
I must admit I am finding it very difficult to find good information on the commands available. I have a book, but that seems to be based on 2003 not 2007 and just getting a list of the commands available seems to be quite a task in itself. Anyway thanks again and on with the project. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
cksm4 | Word VBA | 13 | 07-02-2019 07:48 PM |
retrieving notes in outlook that were deleted | donbmar | Outlook | 0 | 05-21-2011 12:18 PM |
![]() |
TessaLee | Word | 1 | 03-11-2011 12:51 AM |
Package for CD with links to Windows media player content and Flash Shockwave content | hectorh | PowerPoint | 4 | 10-15-2009 12:22 PM |
Templates: automatic text generation from Rich Text content control | Chickenmunga | Word | 0 | 10-01-2008 11:16 AM |