Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Reference a workbook chosen by a user from a userform

I am working on a spreadsheet from which a user can choose to import
data from a saved workbook. Once the user has chosen the import
workbook through a file chooser dialog, it is opened and checked for
validity. The user then chooses the subset of the data they want
through a simple userform.

How can I get a reference to the workbook that has been chosen and
opened so that I can act upon it from the userform or the procedure
that calls the userform? There is no code in the import workbook as it
is just raw data.

Is this a place for a global variable?

Thanks.

Mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Reference a workbook chosen by a user from a userform

How is the user choosing the workbook, and how are you opening it ?

It would be helpful to show some of the code you already have.

Tim



"Mark Hanley" wrote in message
...
I am working on a spreadsheet from which a user can choose to import
data from a saved workbook. Once the user has chosen the import
workbook through a file chooser dialog, it is opened and checked for
validity. The user then chooses the subset of the data they want
through a simple userform.

How can I get a reference to the workbook that has been chosen and
opened so that I can act upon it from the userform or the procedure
that calls the userform? There is no code in the import workbook as it
is just raw data.

Is this a place for a global variable?

Thanks.

Mark



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Reference a workbook chosen by a user from a userform

You could use a public variable. Declare it outside the procedure in the
public module at the top.

Public myWBVar As Workbook

Sub somename()
'Your procedure code
End sub

The time to Set the workbook to the variable is when you open it.


'code to open workbook
yWBVar = ActiveWorkbook

Now your public variable is initialized with the workbook containing the
data, so that if you make another workbook active, myWBVar will still refer
to the one with the data until you Set it to another value.



"Mark Hanley" wrote in message
...
I am working on a spreadsheet from which a user can choose to import
data from a saved workbook. Once the user has chosen the import
workbook through a file chooser dialog, it is opened and checked for
validity. The user then chooses the subset of the data they want
through a simple userform.

How can I get a reference to the workbook that has been chosen and
opened so that I can act upon it from the userform or the procedure
that calls the userform? There is no code in the import workbook as it
is just raw data.

Is this a place for a global variable?

Thanks.

Mark



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Reference a workbook chosen by a user from a userform

Set a reference when the workbook is opened:

Dim wb As Workbook, s As String
s = Application.GetOpenFilename()
Set wb = Workbooks.Open(s)
--
Gary''s Student - gsnu200909


"Mark Hanley" wrote:

I am working on a spreadsheet from which a user can choose to import
data from a saved workbook. Once the user has chosen the import
workbook through a file chooser dialog, it is opened and checked for
validity. The user then chooses the subset of the data they want
through a simple userform.

How can I get a reference to the workbook that has been chosen and
opened so that I can act upon it from the userform or the procedure
that calls the userform? There is no code in the import workbook as it
is just raw data.

Is this a place for a global variable?

Thanks.

Mark
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Reference a workbook chosen by a user from a userform

Another option:

Sub test()

Dim strFilePath As String

On Error Resume Next 'for if nil selected
With Application.FileDialog(msoFileDialogOpen)
.Filters.Add "Excel workbooks", "*.xls"
.FilterIndex = .Filters.Count
.Show
.Execute
strFilePath = .SelectedItems.Item(1)
End With

If Len(strFilePath) = 0 Then
Exit Sub
End If

'now do whatever is needed with the file strFilePath
MsgBox strFilePath, , "opened workbook"

End Sub


RBS


"Mark Hanley" wrote in message
...
I am working on a spreadsheet from which a user can choose to import
data from a saved workbook. Once the user has chosen the import
workbook through a file chooser dialog, it is opened and checked for
validity. The user then chooses the subset of the data they want
through a simple userform.

How can I get a reference to the workbook that has been chosen and
opened so that I can act upon it from the userform or the procedure
that calls the userform? There is no code in the import workbook as it
is just raw data.

Is this a place for a global variable?

Thanks.

Mark


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
save user inputs from userform in a seperate workbook sam Excel Programming 6 July 16th 09 07:59 AM
Data on UserForm to different sheet based on day of week chosen? JennLee Excel Programming 3 March 6th 07 04:01 PM
VBA: Opening a .txt chosen by the user [email protected] Excel Programming 2 May 17th 06 06:42 AM
problem sharing an excel workbook when my formulas reference user. Waiward Engineer Excel Programming 1 March 1st 05 05:41 PM
User Option to save to chosen destination patterson_m[_4_] Excel Programming 1 October 13th 03 05:41 PM


All times are GMT +1. The time now is 07:28 AM.

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"