Import a spreadsheet

  • Thread starter Thread starter Spencer Hutton
  • Start date Start date
S

Spencer Hutton

can anyone help me with importing one spreadsheet into another. the sheet
to be imported has about 200 rows and about 10 columns. i basically want to
attempt to use the GetOpenFilename method to select the file, and copy and
paste the text into the active sheet. TIA.
 
Hi, give this a try:

'############################################
Dim Fname$, ParentBook$
ParentBook = ActiveBook.Name
MsgBox "Select file."
On Error GoTo 0
FName = Application.GetOpenFilename
If FName = "False" Then
MsgBox "You failed to File. This will end the process.",
vbOKOnly
Exit Sub
End If
Err.Clear
Range("A1:C19").Select 'Whatever range you want
Selection.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = True
Cells(1,1).Select
ActiveSheet.Paste
'###################################

HTH--Lonnie M.
 
Hi, you may also want to take a look at the Copy Before function, it
looks something like this:

Sheets("myOriginalWorksheet").Copy
Before:=Workbooks("myGetOpenWorkbook").Sheets(1)

Regards--Lonnie M.
 
Let me make a correction to my above example, I changed my thought
process in mid stream:

'############################################
Dim Fname$, ParentBook$, CildBook$
ParentBook = ActiveBook.Name
MsgBox "Select file."
On Error GoTo 0
FName = Application.GetOpenFilename
If FName = "False" Then
MsgBox "You failed to File. This will end the process.",
vbOKOnly
Exit Sub
End If
Err.Clear
ChildBook = ActiveWorkbook.Name
Range("A1:C19").Select 'Whatever range you want
Selection.Copy
Workbooks(ParentBook).Activate
Cells(1,1).Select
ActiveSheet.Paste
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
'###################################
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top