zachvaldez
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"
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"
You can get the value of a textbox in the current document by using ActiveDocument.fieldname like this:
With respect to your example, you may want to check for a value in the field before saving.
Note: If a document with that name exists, it will be overwritten without prompt the user
strGroupID = ActiveDocument.groupID
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
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.Shap eRange.Ite m(1).TextF rame.TextR ange.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
activedocument.Bookmarks("
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
ASKER
BTW in
strgroupid = Activedocument.groupid -- I get error not supported
so i did this
Dim strGroupID As String
strGroupID = ActiveDocument.Bookmarks.I tem(18).Ra nge.Text
but came out empty - no value ""
strgroupid = Activedocument.groupid -- I get error not supported
so i did this
Dim strGroupID As String
strGroupID = ActiveDocument.Bookmarks.I
but came out empty - no value ""
ASKER
groupid does not show in intellisense
strGroupID = ActiveDocument.groupID
strGroupID = ActiveDocument.groupID
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
Shape, Forms, ActiveX or Content control?
ASKER
i use 2010 version
Note if it is a basic textbox then the sve is as simple as:
ActiveDocument.SaveAs activedocument.SaveAs2(rep lace(activ edocument. Bookmarks( "groupid") .Range.Sha peRange.It em(1).Text Frame.Text Range.Text , vbcr, ""))
Options.SendMailAttach = True
ActiveDocument.SendMail
Chris
ActiveDocument.SaveAs activedocument.SaveAs2(rep
Options.SendMailAttach = True
ActiveDocument.SendMail
Chris
ASKER
chris , I got compile error running the code
ASKER
For future reerences ,This is the correct code!
strxxx = ActiveDocument.Bookmarks.I tem("Group ID").Range .Text
GOT IT!
strxxx = ActiveDocument.Bookmarks.I
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
Chris
ASKER
The .item need to be there to work
.item is the default. In VBA you can omit it.
ASKER
Without the .item,returns
""
""
Chris