Re: Pass between modules

Tech-Archive recommends: Fix windows errors by optimizing your registry



Dave,

I have shown below an extract of the code, which for whatever reason doesn't
seem to retain the string XLSFileNAme from Module1 into Module2.

Don't seem to be able to figure this one out. Regards, Rob

Option Explicit

'Declare for use throughout project
Public XLSFileName As String

Sub Module1()

Dim FileExtStr As String
Dim FileFormatNum As Long
Dim DefPath As String

DefPath = "C:\My Documents\Development\Reports"

'Name of the Excel file with a date/time stamp
XLSFileName = DefPath & "NewFileTest " & _
Format(Now, "dd-mmm-yyyy h-mm-ss") & FileExtStr

'Prints name of file with full path and name
Debug.Print XLSFileName

Call Module2

End Sub

Option Explicit

Sub Module2()

Debug.Print XLSFileName

'Here I want to use the variable XLSFileName but it's null
MsgBox "This file has been saved to: " & vbNewLine & XLSFileName
End Sub


"Dave Peterson" <petersod@xxxxxxxxxxxxxxxx> wrote in message
news:47EF7ABE.CA88DD9E@xxxxxxxxxxxxxxxxxxx
And I meant another variable that had the same name.

Dave Peterson wrote:

Do you have another variable declared in module 2 (either public or
within the
procedure)?

Rob wrote:

Hi, I have tried to split a piece of code into separate modules for
ease of
knowing what each element does, however, having done this, not all the
code
works as expected. I'm work through the issues one by one but I'm
stuck on
transferring a file's name that's been saved in module 1 to module 2.

Module 1 creates a new file and saves it with a unique name derived
from the
date and time, however, when I then run code in module 2, I'd like to
display after saving this file again its name. I have declared Public
FileName As String in module 1 but regardless what I do in module 2, I
can't
capture FileName declare in module 1. I have Option Explicit set in
all
modules and subs aren't set to Private.

Any pointers welcome. Thanks, Rob

--

Dave Peterson

--

Dave Peterson


.



Relevant Pages

  • Re: Vb Global variables
    ... You'll want to Add a Module, then declare the variable in the ... 'Global gsPathToData As String ... Sub Form_Load, and Private Sub Command1_Click. ...
    (microsoft.public.vb.general.discussion)
  • Re: Pass between modules
    ... Public XLSFileName As String ... Sub Module2() ... Dave Peterson wrote: ... capture FileName declare in module 1. ...
    (microsoft.public.excel.programming)
  • Re: Pass between modules
    ... Public XLSFileName As String ... Sub Module2() ... Dave Peterson wrote: ... capture FileName declare in module 1. ...
    (microsoft.public.excel.programming)
  • Re: Problem with passing parameter
    ... Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, ... Public Sub WriteData(ByVal Data As Variant, ByVal Length As Integer, ByRef ... RecData As String) ...
    (microsoft.public.vb.general.discussion)
  • Re: Error Trapping
    ... ByVal lpHelpFile As String, _ ... Declare Function HtmlHelp Lib "HHCtrl.ocx" Alias "HtmlHelpA" _ ... Private Sub CommandButton1_Click ... > to a help file, but I don't have a help file that I've built. ...
    (microsoft.public.word.vba.general)