B
Baine
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
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