Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Redirecting output of a command in a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KLH - 28 Feb 2007 19:27 GMT
I'm trying to do something similar to redirecting output in DOS and shell
scripting, where you can use the output from one command as the input for
another command.

I'm trying to create a macro that will create a bookmark name by copying and
pasting a bit of text from the document.  At one point in the macro there is
this command:

   Selection.Copy

This copies the text that I want to use as a macro name.  Later, there is
this section:

 With ActiveDocument.Bookmarks
       .Add Range:=Selection.Range, Name:="Bkmk1"
       .DefaultSorting = wdSortByName
       .ShowHidden = False

The problem is, every time I run the macro, it uses "Bkmk1" as the input for
the bookmark name.  Is there a way to set the text copied in the first
command as a variable, and then use the value of that variable for the
bookmark name?
Greg Maxey - 28 Feb 2007 19:47 GMT
Provided your selected text represents a "valid" bookmark name:

Sub Test()
Dim pStr As String
pStr = Selection.Text
Bookmark?
With ActiveDocument.Bookmarks
  .Add Range:=Selection.Range, Name:=pStr
  .DefaultSorting = wdSortByName
  .ShowHidden = False
End With
End Sub

otherwise you will need to incorporate some error handling.

> I'm trying to do something similar to redirecting output in DOS and shell
> scripting, where you can use the output from one command as the input for
[quoted text clipped - 18 lines]
> command as a variable, and then use the value of that variable for the
> bookmark name?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.