LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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


 
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 12:00 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"