Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default PUBLIC VARIABLE for SELECTEDFILE

I have one sub that opens the file selection dialog. Then I want to copy
some cells from the Excel file that was just opened to the MasterData.XLS
file where the Module resides. I don't know what the file name might be but
I need to refer back to that file on several occations to copy all of the
cells. The data needed in not allways in the same row or column. I know
how to do the coding to locate the data and copy it. How do I refer to the
file that was opened in the first sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", , "Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default PUBLIC VARIABLE for SELECTEDFILE

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFileFullName As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFileFullName = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If
' Workbooks(2).Activate
ThisWorkbook.Activate
Next
End Sub

--
Regards,
Tom Ogilvy


"Baine" wrote in message
...
I have one sub that opens the file selection dialog. Then I want to copy
some cells from the Excel file that was just opened to the MasterData.XLS
file where the Module resides. I don't know what the file name might be
but I need to refer back to that file on several occations to copy all of
the cells. The data needed in not allways in the same row or column. I
know how to do the coding to locate the data and copy it. How do I refer
to the file that was opened in the first sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default PUBLIC VARIABLE for SELECTEDFILE

Thanks for the help Tom. I tried your code and was unable to do any better
on the main question I had. How do I refer to the file that was opened in
the first sub when I use the second sub in the same module?

"Tom Ogilvy" wrote in message
...
Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFileFullName As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFileFullName = Application.GetOpenFilename("Files (*.xls),*.xls",
, "Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If
' Workbooks(2).Activate
ThisWorkbook.Activate
Next
End Sub

--
Regards,
Tom Ogilvy


"Baine" wrote in message
...
I have one sub that opens the file selection dialog. Then I want to copy
some cells from the Excel file that was just opened to the MasterData.XLS
file where the Module resides. I don't know what the file name might be
but I need to refer back to that file on several occations to copy all of
the cells. The data needed in not allways in the same row or column. I
know how to do the coding to locate the data and copy it. How do I refer
to the file that was opened in the first sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default PUBLIC VARIABLE for SELECTEDFILE

I change you second declarationof SelectFile in OpenInvoice to a different
variable name so it didn't block you public variable. And added code to
assign the name of the newly opened workbook to the public variable for
future use. I didn't alter your second procedure since it wasn't clear what
you wanted to do there. As written, it does nothing explicitely with the
public variable. I did miss changing one line in the corrected version of
your first routine. Here is a revision

Option Explicit
Public selectedFile As String
Public bk as Workbook

Sub openInvoiceFile()
Dim selectedFileFullName As String
Set Bk = ActiveWorkbook

selectedFileFullName = Application.GetOpenFilename( _
"Files (*.xls),*.xls", , "Select Invoice", , False)

If selectedFileFullName = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If

ThisWorkbook.Activate
End Sub

Here is an example of how to use the variable.

Sub CopyDATAtoMaster()
workbooks(SelectedFile).Activate
worksheets(1).Activate
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
workbooks("SelectedFile).Activate
End Sub


or
Sub CopyDataToMaster1()
Workbooks(Selectedfile).Worksheets(1).Range("B2"). Copy _
Destination:=Workbooks("S2 Master1.xls").Worksheets(1).Range("C5")
End Sub

of course I don't know where your code is located or how many workbooks are
open or which sheet in the workbook you want to use, so this is only a
guess.

Code could contain typos, but should give you a general idea of how to
proceed.

If you want to consolidate information from multiple workbooks and have
little knowledge of coding, perhaps you should look he

http://www.rondebruin.nl/copy3.htm

--
Regards,
Tom Ogilvy



"Baine" wrote in message
...
Thanks for the help Tom. I tried your code and was unable to do any
better on the main question I had. How do I refer to the file that was
opened in the first sub when I use the second sub in the same module?

"Tom Ogilvy" wrote in message
...
Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFileFullName As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFileFullName = Application.GetOpenFilename("Files (*.xls),*.xls",
, "Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If
' Workbooks(2).Activate
ThisWorkbook.Activate
Next
End Sub

--
Regards,
Tom Ogilvy


"Baine" wrote in message
...
I have one sub that opens the file selection dialog. Then I want to copy
some cells from the Excel file that was just opened to the MasterData.XLS
file where the Module resides. I don't know what the file name might be
but I need to refer back to that file on several occations to copy all of
the cells. The data needed in not allways in the same row or column. I
know how to do the coding to locate the data and copy it. How do I refer
to the file that was opened in the first sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
End Sub








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default PUBLIC VARIABLE for SELECTEDFILE

Now that's working for me. Thanks! What is Bk used for in the code?
Public bk as Workbook
Set Bk = ActiveWorkbook

"Tom Ogilvy" wrote in message
...
I change you second declarationof SelectFile in OpenInvoice to a different
variable name so it didn't block you public variable. And added code to
assign the name of the newly opened workbook to the public variable for
future use. I didn't alter your second procedure since it wasn't clear
what you wanted to do there. As written, it does nothing explicitely with
the public variable. I did miss changing one line in the corrected version
of your first routine. Here is a revision

Option Explicit
Public selectedFile As String
Public bk as Workbook

Sub openInvoiceFile()
Dim selectedFileFullName As String
Set Bk = ActiveWorkbook

selectedFileFullName = Application.GetOpenFilename( _
"Files (*.xls),*.xls", , "Select Invoice", , False)

If selectedFileFullName = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If

ThisWorkbook.Activate
End Sub

Here is an example of how to use the variable.

Sub CopyDATAtoMaster()
workbooks(SelectedFile).Activate
worksheets(1).Activate
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
workbooks("SelectedFile).Activate
End Sub


or
Sub CopyDataToMaster1()
Workbooks(Selectedfile).Worksheets(1).Range("B2"). Copy _
Destination:=Workbooks("S2 Master1.xls").Worksheets(1).Range("C5")
End Sub

of course I don't know where your code is located or how many workbooks
are open or which sheet in the workbook you want to use, so this is only a
guess.

Code could contain typos, but should give you a general idea of how to
proceed.

If you want to consolidate information from multiple workbooks and have
little knowledge of coding, perhaps you should look he

http://www.rondebruin.nl/copy3.htm

--
Regards,
Tom Ogilvy



"Baine" wrote in message
...
Thanks for the help Tom. I tried your code and was unable to do any
better on the main question I had. How do I refer to the file that was
opened in the first sub when I use the second sub in the same module?

"Tom Ogilvy" wrote in message
...
Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFileFullName As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFileFullName = Application.GetOpenFilename("Files
(*.xls),*.xls", , "Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If
' Workbooks(2).Activate
ThisWorkbook.Activate
Next
End Sub

--
Regards,
Tom Ogilvy


"Baine" wrote in message
...
I have one sub that opens the file selection dialog. Then I want to
copy some cells from the Excel file that was just opened to the
MasterData.XLS file where the Module resides. I don't know what the
file name might be but I need to refer back to that file on several
occations to copy all of the cells. The data needed in not allways in
the same row or column. I know how to do the coding to locate the data
and copy it. How do I refer to the file that was opened in the first
sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
End Sub












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default PUBLIC VARIABLE for SELECTEDFILE

I didn't actually use it, but I could have <g

instead of
Windows("S2 Master1.xls").Activate
I though I could do
bk.activate
but then I would have assumed that S2 Master1.xls was the activeworkbook
when you opened the new workbook and that would have assumed too much. So I
thought better of it, but didn't remove it from the code or the public
declaration.

--
Regards,
Tom Ogilvy



"Baine" wrote:

Now that's working for me. Thanks! What is Bk used for in the code?
Public bk as Workbook
Set Bk = ActiveWorkbook

"Tom Ogilvy" wrote in message
...
I change you second declarationof SelectFile in OpenInvoice to a different
variable name so it didn't block you public variable. And added code to
assign the name of the newly opened workbook to the public variable for
future use. I didn't alter your second procedure since it wasn't clear
what you wanted to do there. As written, it does nothing explicitely with
the public variable. I did miss changing one line in the corrected version
of your first routine. Here is a revision

Option Explicit
Public selectedFile As String
Public bk as Workbook

Sub openInvoiceFile()
Dim selectedFileFullName As String
Set Bk = ActiveWorkbook

selectedFileFullName = Application.GetOpenFilename( _
"Files (*.xls),*.xls", , "Select Invoice", , False)

If selectedFileFullName = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If

ThisWorkbook.Activate
End Sub

Here is an example of how to use the variable.

Sub CopyDATAtoMaster()
workbooks(SelectedFile).Activate
worksheets(1).Activate
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
workbooks("SelectedFile).Activate
End Sub


or
Sub CopyDataToMaster1()
Workbooks(Selectedfile).Worksheets(1).Range("B2"). Copy _
Destination:=Workbooks("S2 Master1.xls").Worksheets(1).Range("C5")
End Sub

of course I don't know where your code is located or how many workbooks
are open or which sheet in the workbook you want to use, so this is only a
guess.

Code could contain typos, but should give you a general idea of how to
proceed.

If you want to consolidate information from multiple workbooks and have
little knowledge of coding, perhaps you should look he

http://www.rondebruin.nl/copy3.htm

--
Regards,
Tom Ogilvy



"Baine" wrote in message
...
Thanks for the help Tom. I tried your code and was unable to do any
better on the main question I had. How do I refer to the file that was
opened in the first sub when I use the second sub in the same module?

"Tom Ogilvy" wrote in message
...
Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFileFullName As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFileFullName = Application.GetOpenFilename("Files
(*.xls),*.xls", , "Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If
' Workbooks(2).Activate
ThisWorkbook.Activate
Next
End Sub

--
Regards,
Tom Ogilvy


"Baine" wrote in message
...
I have one sub that opens the file selection dialog. Then I want to
copy some cells from the Excel file that was just opened to the
MasterData.XLS file where the Module resides. I don't know what the
file name might be but I need to refer back to that file on several
occations to copy all of the cells. The data needed in not allways in
the same row or column. I know how to do the coding to locate the data
and copy it. How do I refer to the file that was opened in the first
sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
End Sub











  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default PUBLIC VARIABLE for SELECTEDFILE

Thanks! That does it.

"Tom Ogilvy" wrote in message
...
I didn't actually use it, but I could have <g

instead of
Windows("S2 Master1.xls").Activate
I though I could do
bk.activate
but then I would have assumed that S2 Master1.xls was the activeworkbook
when you opened the new workbook and that would have assumed too much. So
I
thought better of it, but didn't remove it from the code or the public
declaration.

--
Regards,
Tom Ogilvy



"Baine" wrote:

Now that's working for me. Thanks! What is Bk used for in the code?
Public bk as Workbook
Set Bk = ActiveWorkbook

"Tom Ogilvy" wrote in message
...
I change you second declarationof SelectFile in OpenInvoice to a
different
variable name so it didn't block you public variable. And added code to
assign the name of the newly opened workbook to the public variable for
future use. I didn't alter your second procedure since it wasn't clear
what you wanted to do there. As written, it does nothing explicitely
with
the public variable. I did miss changing one line in the corrected
version
of your first routine. Here is a revision

Option Explicit
Public selectedFile As String
Public bk as Workbook

Sub openInvoiceFile()
Dim selectedFileFullName As String
Set Bk = ActiveWorkbook

selectedFileFullName = Application.GetOpenFilename( _
"Files (*.xls),*.xls", , "Select Invoice", , False)

If selectedFileFullName = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If

ThisWorkbook.Activate
End Sub

Here is an example of how to use the variable.

Sub CopyDATAtoMaster()
workbooks(SelectedFile).Activate
worksheets(1).Activate
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
workbooks("SelectedFile).Activate
End Sub


or
Sub CopyDataToMaster1()
Workbooks(Selectedfile).Worksheets(1).Range("B2"). Copy _
Destination:=Workbooks("S2 Master1.xls").Worksheets(1).Range("C5")
End Sub

of course I don't know where your code is located or how many workbooks
are open or which sheet in the workbook you want to use, so this is
only a
guess.

Code could contain typos, but should give you a general idea of how to
proceed.

If you want to consolidate information from multiple workbooks and have
little knowledge of coding, perhaps you should look he

http://www.rondebruin.nl/copy3.htm

--
Regards,
Tom Ogilvy



"Baine" wrote in message
...
Thanks for the help Tom. I tried your code and was unable to do any
better on the main question I had. How do I refer to the file that
was
opened in the first sub when I use the second sub in the same module?

"Tom Ogilvy" wrote in message
...
Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFileFullName As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFileFullName = Application.GetOpenFilename("Files
(*.xls),*.xls", , "Select
Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFileFullName
SelectedFile = ActiveWorkbook.Name
End If
' Workbooks(2).Activate
ThisWorkbook.Activate
Next
End Sub

--
Regards,
Tom Ogilvy


"Baine" wrote in message
...
I have one sub that opens the file selection dialog. Then I want to
copy some cells from the Excel file that was just opened to the
MasterData.XLS file where the Module resides. I don't know what the
file name might be but I need to refer back to that file on several
occations to copy all of the cells. The data needed in not allways
in
the same row or column. I know how to do the coding to locate the
data
and copy it. How do I refer to the file that was opened in the first
sub?

Option Explicit
Public selectedFile As String
' Public selectedFile As Workbook
' Brings up dialog to select invoice file to
' copy data to Master file.

Sub openInvoiceFile()
Dim selectedFile As String
Dim wbToOpen As Integer, wsCount As Integer
Dim objWsQBRfreeB As String
For wbToOpen = 1 To 1
'display dialog asking user to select a file
selectedFile = Application.GetOpenFilename("Files (*.xls),*.xls", ,
"Select Invoice", , False)
'check if cancel selected then open
If selectedFile = "False" Then
MsgBox "You choose to interrupt loading files."
Exit For
Else
Workbooks.OpenText Filename:=selectedFile
End If
' Workbooks(2).Activate
Next
End Sub
--------------------------------------------------------------------------------
Sub CopyDATAtoMaster()
'
' CopyDATAtoMaster Macro
' Macro recorded 10/6/2006 by Baine-64
'
Range("B2").Select
Selection.Copy
Windows("S2 Master1.xls").Activate
Range("C5").Select
ActiveSheet.Paste
' Windows(selectedFile).Activate
' Set selectedFile = ActiveWorkbook
' selectedFile.Activate
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
Disappearing Public Variable donbowyer Excel Programming 8 September 20th 06 07:42 PM
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
declaring public variable value Damon Excel Programming 4 July 24th 05 02:59 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


All times are GMT +1. The time now is 07:50 PM.

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

About Us

"It's about Microsoft Excel"