Solved

word VBA question

Posted on 2011-02-11
15
505 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 6

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
 

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 300 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
A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now