View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 1,726
Default Open File then Set as

Dim sFile
sFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If sFile < False Then
Set xlBook = Workbook.Open(sFile)
End If


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"MacroLearning" wrote in message
...
Hi all,
I have a macro that works as I want. When I first started building I
included the original filename to copy from. That file will change every
month. So I want the user to open the file, when the file is opened, it
will
become "xlBook1". following is the code. I'm getting a debug at that
point,
but am not sure how to get past it.

Any help will be very much appreciated!

'Book 1 is Headcount by Detail Report
Dim xlBook1 As Excel.Workbook
'Book 2 is Quirk (all except SSGA)
Dim xlBook2 As Excel.Workbook
'Sheet7 is HC Summary worksheet from HC Detail Report
Dim xlSheet7 As Excel.Worksheet
'Sheet8 is HC Summary worksheet for Quirk
Dim xlSheet8 As Excel.Worksheet

'Copy and Paste from Headcount Detail to Quirk
Set xlBook1 = Application.GetOpenFilename <=====This is the problem here
Set xlSheet1 = xlBook1.Worksheets("Headcount Detail")
Set xlBook2 = Workbooks.Open( _
"C:\\Distribution File Cuts\Headcount by Title - Quirk.xls")
Set xlSheet2 = xlBook2.Worksheets("Headcount Detail")
Set xlSheet7 = xlBook1.Worksheets("Headcount Summary")
Set xlSheet8 = xlBook2.Worksheets("Headcount Summary")
xlSheet1.Range("A1:H232").Copy xlSheet2.Range("A1")
xlSheet7.Range("A1:J21").Copy xlSheet8.Range("A1")
xlSheet2.Rows("40:47").Delete