word VBA question

I created a module..

Sub_Sendit

ActiveDocument.SaveAs ("C:\ABC\Check.doc")
Options.SendMailAttach = True
ActiveDocument.SendMail

End sub

However, I have a textbox in the document and named it bookmark as "GroupID".
Id ike to refernce it  when as save it instead of

"C:\ABC\Check.doc",

should append the groupID as


 ("C:\ABC\Check8888.doc")

with 888 is the value entered on the textbox with bookmarked "groupid"
zachvaldezAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
You should be able to get the text contained within a bookmark:

strText = ActiveDocument.Bookmarks("MyBookmark").Range.Text

However it might help if you tell us what sort of text box is it. Is it a Shape, Forms, ActiveX or Content control?
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Can you provide an example with the text box so we can see the implementation ... delete anything else but the textbox and bookmark

Chris
0
 
pdoelleCommented:
You can get the value of a textbox in the current document by using ActiveDocument.fieldname like this:

strGroupID = ActiveDocument.groupID

Open in new window


With respect to your example, you may want to check for a value in the field before saving.  

Dim strGroupID As String
strGroupID = ActiveDocument.groupID
If Len(strGroupID) > 0 Then
  ActiveDocument.SaveAs ("C:\Temp\Check" & strGroupID & ".doc")
  Options.SendMailAttach = True
  ActiveDocument.SendMail
Else
  MsgBox "The Group ID is Empty. Please enter a group ID and try again", vbOKOnly, "Information Missing"
End If

Open in new window


Note: If a document with that name exists, it will be overwritten without prompt the user
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Chris BottomleySoftware Quality Lead EngineerCommented:
Assuming a standard text box from the word application then I would suggest:

activedocument.Bookmarks("groupid").Range.ShapeRange.Item(1).TextFrame.TextRange.Text

If it isn't the first shape then you need to identify the correct shape but it sounds as though it might be the only one therefore ...

Chris
0
 
zachvaldezAuthor Commented:
BTW in
strgroupid = Activedocument.groupid -- I get error not supported
so i did this

Dim strGroupID As String
strGroupID = ActiveDocument.Bookmarks.Item(18).Range.Text
but came out empty - no value ""
0
 
zachvaldezAuthor Commented:
groupid  does not show in  intellisense

strGroupID = ActiveDocument.groupID
0
 
zachvaldezAuthor Commented:
well, if you select insert in the main menu , I see a textbox which i use to draw. Im not sure what describes the source whether

 Shape, Forms, ActiveX or Content control?
0
 
zachvaldezAuthor Commented:
i use 2010 version
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Note if it is a basic textbox then the sve is as simple as:

ActiveDocument.SaveAs activedocument.SaveAs2(replace(activedocument.Bookmarks("groupid").Range.ShapeRange.Item(1).TextFrame.TextRange.Text, vbcr, ""))
Options.SendMailAttach = True
ActiveDocument.SendMail

Chris
0
 
zachvaldezAuthor Commented:
chris , I got compile error running the code
0
 
zachvaldezAuthor Commented:
For future reerences ,This is the correct code!
strxxx = ActiveDocument.Bookmarks.Item("GroupID").Range.Text

GOT IT!
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
AH well ... like I asked at the outset and Graham later it helps to see a sample of what you are using.  In point of fact what you have used is as suggested by Graham in http:#34872932

Chris
0
 
zachvaldezAuthor Commented:
The .item need to be there to work
0
 
GrahamSkanRetiredCommented:
.item is the default. In VBA you can omit it.
0
 
zachvaldezAuthor Commented:
Without the .item,returns
 ""
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.