Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

word VBA question

Posted on 2011-02-11
15
Medium Priority
?
556 Views
Last Modified: 2012-05-11
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"
0
Comment
Question by:zachvaldez
  • 8
  • 4
  • 2
  • +1
15 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34872345
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
 
LVL 7

Expert Comment

by:pdoelle
ID: 34872426
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34872628
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

Author Comment

by:zachvaldez
ID: 34872699
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
 

Author Comment

by:zachvaldez
ID: 34872843
groupid  does not show in  intellisense

strGroupID = ActiveDocument.groupID
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1200 total points
ID: 34872932
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
 

Author Comment

by:zachvaldez
ID: 34873006
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
 

Author Comment

by:zachvaldez
ID: 34873011
i use 2010 version
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34873029
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
 

Author Comment

by:zachvaldez
ID: 34873999
chris , I got compile error running the code
0
 

Author Comment

by:zachvaldez
ID: 34874261
For future reerences ,This is the correct code!
strxxx = ActiveDocument.Bookmarks.Item("GroupID").Range.Text

GOT IT!
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34874294
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
 

Author Comment

by:zachvaldez
ID: 34875537
The .item need to be there to work
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 34877467
.item is the default. In VBA you can omit it.
0
 

Author Closing Comment

by:zachvaldez
ID: 34878289
Without the .item,returns
 ""
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question