Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Pass Argument?

I need to pass the file path and name select by the cmdBrowse_Click sub into
the Open_Data_File sub when the cmdOK_Click sub is fired.

How do I fix the code below to accomplish this?

Thanks,
Hal

Option Explicit

Private Sub cmdBrowse_Click()

Dim FileToOpen As Variant
FileToOpen = Application _
.GetOpenFilename("DAT Files (*.dat), *.dat")
If FileToOpen = False Then
txtFileToOpen.Value = ""
Else
txtFileToOpen.Value = FileToOpen
End If
cmdOK.Enabled = True
cmdOK.SetFocus

End Sub


Private Sub cmdOK_Click()
Open_Data_File
End Sub



Sub Open_Data_File()

Workbooks.OpenText Filename:=FileToOpen, Origin:= _
437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit
Columns("A:A").Select
Selection.ColumnWidth = 8.43
Range("A1").Select

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Pass Argument?

You can create a global variable to hold the file name, just define your
FileToOpen variable at the top of the module, before any Subs or Functions,
like so:
Private FileToOpen as String

If the code you have is in more than one module, though, you need to make it
Public:
Public FileToOpen as String

Private variables keep their values and can be used by any code in the
module they are in; Public allows them to be used in any module in your
project.
--
- K Dales


"Hal" wrote:

I need to pass the file path and name select by the cmdBrowse_Click sub into
the Open_Data_File sub when the cmdOK_Click sub is fired.

How do I fix the code below to accomplish this?

Thanks,
Hal

Option Explicit

Private Sub cmdBrowse_Click()

Dim FileToOpen As Variant
FileToOpen = Application _
.GetOpenFilename("DAT Files (*.dat), *.dat")
If FileToOpen = False Then
txtFileToOpen.Value = ""
Else
txtFileToOpen.Value = FileToOpen
End If
cmdOK.Enabled = True
cmdOK.SetFocus

End Sub


Private Sub cmdOK_Click()
Open_Data_File
End Sub



Sub Open_Data_File()

Workbooks.OpenText Filename:=FileToOpen, Origin:= _
437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit
Columns("A:A").Select
Selection.ColumnWidth = 8.43
Range("A1").Select

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function (array argument, range argument, string argument) vba Witek[_2_] Excel Programming 3 April 24th 05 03:12 PM
can a userform pass an argument? smokiibear Excel Programming 12 December 8th 04 02:14 AM
pass argument to macro tommy Excel Programming 4 September 1st 04 06:21 PM
Pass an argument to Excel workbook dorothy lo Excel Programming 2 April 22nd 04 04:05 AM
How to pass an Excel range as an argument to a SQL Server stored Procedure Belinda Excel Programming 7 April 8th 04 11:24 AM


All times are GMT +1. The time now is 04:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"