Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

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"
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you provide an example with the text box so we can see the implementation ... delete anything else but the textbox and bookmark

Chris
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
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
Avatar of zachvaldez

ASKER

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 ""
groupid  does not show in  intellisense

strGroupID = ActiveDocument.groupID
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
i use 2010 version
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
chris , I got compile error running the code
For future reerences ,This is the correct code!
strxxx = ActiveDocument.Bookmarks.Item("GroupID").Range.Text

GOT IT!
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
The .item need to be there to work
.item is the default. In VBA you can omit it.
Without the .item,returns
 ""