Using a Range variable to call a procedure with a ByValstatement...
Why use a loop to see if a file exists in a folder? You can use the
Dir function, or if you want to use FSO, use the FileExists method
(returns True if a file exists).
You are confusing the rest of us (and maybe also confuse Excel itself)
by using reserved words for your sub name (Workbook_Open, Sheet_Open).
You should give your subs names that describe their purpose.
i.e.
Sub Find_And_Open(ByVal FileName As String, ByVal CutRange As Range)
Sub UpdateWorkbooks(ByVal FileName As String, ByVal CutRange As Range)
Also I believe ByVal is the default for arguments, you don't need to
include it with every argument. Subs may be sped up by passing ranges
ByRef. (My memory of "Professional Excel Development" is shaky right
now, someone else correct me if I'm wrong on either of these counts).
To call a procedure with arguments, you have to pass arguments to it
(in parenthesis) that are the same type as the variable type you
specified. You don't include the variable names in the arguments, as
you did in your first post. So if your sub is named
Private Sub Sheet_Open(ByVal FileName As String, ByVal CutRange As
Range)
Then you call it from another macro like this:
Sheet_Open("MyFile.xls", Range("A1"))
You can use variables that represent these, as long as the variables
are the same type. For example
Dim strFileN As String
Dim rng As Excel.Range
strFileN = "MyFile.xls"
Set rng = Range("A1")
Sheet_Open(strFileN, rng)
HTH,
JP
On Sep 17, 3:37*pm, R Tanner wrote:
Okay sorry...I should have given more details...
I have a separate procedure that is creating a filesystemobject and
then running through every file in a folder and checking to see if
there is a file with a specific name. *If there is not, it creates it,
copies data into it, and then closes it. *If there is, then it opens
it, appends data to the end of the file, and closes it, saving
changes. *I have two arguments I want to pass to this procedure. *One
is the file name to check for. *The second argument I want to pass to
it is the RangeToCopy...Here is my code...
|