Passing Variables between Macros In Word

V

VexedFist

I am trying to pass a Variable between Macros (Main and Analog) in MS-Word.
The user enters a Number in the message box. This is used to open multiple
Files that start with this number.
The Complete filename are: 123456_Analog65.txt and 123456_Digtial65.txt
etc...
This is only a small part of a large macro I want to use on multiple files
Example Macro:

Sub Main()
Dim Message, Title, Default
Dim Cmr As String
Message = "Enter New File Name:" ' Set prompt.
Title = "File Will be saved with this Name" ' Set title.
Default = " " ' Set default.
Cmr = InputBox(Message, Title, Default)
Application.Run MacroName:="Analog"
Application.Run MacroName:="Digital"
end sub

Sub Analog()
Dim MyRawData As String
Dim MyReconfiguredData As String
Underscore = "_"
Rawdir = "C:\"
Rawdata = "Analog65.txt"
MyRawData = Rawdir + Cmr + Underscore + Rawdata
MyReconfiguredData = "Analog65.txt"
ChangeFileOpenDirectory "C:\"
Documents.Open FileName:=MyRawData, ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto
Selection.Find.ClearFormatting
With Selection.Find
.Text = "H500: AMO SCSU STARTED"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
end sub

Any assistance will be greatly appreciated
 
D

Doug Robbins - Word MVP

See response to your post with the subject "MS-Word 2003 VBA Variable
Question" in the vba.general newsgroup.

Please do not post the same question separately to multiple newsgroups.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
V

VexedFist

Doug,

I already had the text you supplied below in my MAIN macro.
The problem I have is when I run the sub macros,
that put the file names together I get teh following ERROR.

Run Time Error 5174

This file could not be found
Try one or more of the following:
* Check the spelling of the name of the document
* Try a different file name.
(C:\_Analog65.txt)


Your assistance in this matter will be greatly appreciated.


Sub Analog()
Dim MyRawData As String
Dim MyReconfiguredData As String
Underscore = "_"
Rawdir = "C:\"
Rawdata = "Analog65.txt"
MyRawData = Rawdir + Cmr + Underscore + Rawdata
MyReconfiguredData = "Analog65.txt"
ChangeFileOpenDirectory "C:\"
Documents.Open FileName:=MyRawData, ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:=""
_
end sub

The problem I get is an ERROR when using CMR 123456, see below:
 
D

Doug Robbins - Word MVP

Have you declared CMR as Public?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top