View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Copy from one workbook to another


Dim sFile As String
Dim oWb As Workbook

sFile = "c:\mytest\myfile..xls"
On Error Resume Next
Set oWb = Workbooks.Open (sFile)
On Errtor Goto 0
If oWb Is Nothing Then
MsgBox "File not found"
Else
ThisWorkbook.Worksheets("Sheet1").Range("A1:H100") .Copy _
oWb.Worksheets("Sheet1").Range("A1")
End If

You could also use GetOpenFileName to use a dialog box to navigate to the
file and open that

Dim sFile As String
Dim oWb As Workbook

sFile = "c:\mytest\myfile..xls"
On Error Resume Next
File = Application.GetOpenFilename( _
"Microsft Excel Files (*.xls), *.xls")
If sFile < False Then
Set oWb = Workbooks.Open(sFile)
On Errtor GoTo 0
If oWb Is Nothing Then
MsgBox "File not found"
Else
ThisWorkbook.Worksheets("Sheet1").Range("A1:H100") .Copy _
oWb.Worksheets("Sheet1").Range("A1")
End If
End If

And it is appreciated :-)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ole" wrote in message
...
Hi,

I want to copy som cells from workbook 1 to a closed workbook 2 with a
commanbutton,
when i click the command button from workbook1 i want i to open workbook2
and copy the
cells to workbook2, anyone got an idea.

Any help is apressiaded ( and that i cant spell to :-)

Ole


--
Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
Den har indtil videre sparet mig for at få 0 spam-mails.
Betalende brugere får ikke denne besked i deres e-mails.
Hent den gratis her: www.spamfighter.dk