Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Import Worksheets and "Overright"

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub


--
Your guidance is greatly appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Import Worksheets and "Overright"

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next


dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Import Worksheets and "Overright"

Thanks Dave but I need just a little more help. I incorporated your code and
here is what I have. Its hanging on the

Wks.Cell.Copy lines...... Also notice I commented out the Next wks.... that
also was hanging

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New
'For each wks in mybook.worksheets
For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

'Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
--
Your guidance is greatly appreciated!


"Dave Peterson" wrote:

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next


dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Import Worksheets and "Overright"

Why did you drop the "For each wks in mybook.worksheets" and the corresponding
"next wks" lines?

Apprentice wrote:

Thanks Dave but I need just a little more help. I incorporated your code and
here is what I have. Its hanging on the

Wks.Cell.Copy lines...... Also notice I commented out the Next wks.... that
also was hanging

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New
'For each wks in mybook.worksheets
For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

'Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
--
Your guidance is greatly appreciated!

"Dave Peterson" wrote:

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next


dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Import Worksheets and "Overright"

Don't know why.... my bad. It works great now thankyou.

I forworded the workbook with code to a counterpart. We adjusted the path
to meet his file structure. On his PC the code works great until this line:

wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas

basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

We both have the same versions of Excel and all other things are equal, but
the error says "out of range".

What would cause the code to not work on anothers PC?

Any ideas?

Here is the whole code:

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\bekuta\My Documents\Kuta\work\tech
assistance\hrmc\Employee Survey\ES2009\OrgWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New

For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
For Each wks In mybook.Worksheets
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats



Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

Thanks for your time Dave



--
Your guidance is greatly appreciated!


"Dave Peterson" wrote:

Why did you drop the "For each wks in mybook.worksheets" and the corresponding
"next wks" lines?

Apprentice wrote:

Thanks Dave but I need just a little more help. I incorporated your code and
here is what I have. Its hanging on the

Wks.Cell.Copy lines...... Also notice I commented out the Next wks.... that
also was hanging

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New
'For each wks in mybook.worksheets
For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

'Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
--
Your guidance is greatly appreciated!

"Dave Peterson" wrote:

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next

dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Import Worksheets and "Overright"

Don't know why.... my bad. It works great now thankyou.

I forworded the workbook with code to a counterpart. We adjusted the path
to meet his file structure. On his PC the code works great until this line:

wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas

basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

We both have the same versions of Excel and all other things are equal, but
the error says "out of range".

What would cause the code to not work on anothers PC?

Any ideas?

Here is the whole code:

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\bekuta\My Documents\Kuta\work\tech
assistance\hrmc\Employee Survey\ES2009\OrgWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New

For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
For Each wks In mybook.Worksheets
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats



Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

Thanks for your time Dave



--
Your guidance is greatly appreciated!


"Dave Peterson" wrote:

Why did you drop the "For each wks in mybook.worksheets" and the corresponding
"next wks" lines?

Apprentice wrote:

Thanks Dave but I need just a little more help. I incorporated your code and
here is what I have. Its hanging on the

Wks.Cell.Copy lines...... Also notice I commented out the Next wks.... that
also was hanging

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New
'For each wks in mybook.worksheets
For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

'Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
--
Your guidance is greatly appreciated!

"Dave Peterson" wrote:

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next

dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!

--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Import Worksheets and "Overright"

Why did you drop the "For each wks in mybook.worksheets" and the corresponding
"next wks" lines?

Apprentice wrote:

Thanks Dave but I need just a little more help. I incorporated your code and
here is what I have. Its hanging on the

Wks.Cell.Copy lines...... Also notice I commented out the Next wks.... that
also was hanging

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New
'For each wks in mybook.worksheets
For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

'Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
--
Your guidance is greatly appreciated!

"Dave Peterson" wrote:

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next


dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Import Worksheets and "Overright"

Thanks Dave but I need just a little more help. I incorporated your code and
here is what I have. Its hanging on the

Wks.Cell.Copy lines...... Also notice I commented out the Next wks.... that
also was hanging

Sub Import()

Dim basebook As Workbook
Dim mybook As Workbook
Dim wks As Worksheet
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook
'New
'For each wks in mybook.worksheets
For N = LBound(FName) To UBound(FName)

Set mybook = Workbooks.Open(FName(N))
wks.Cells.Copy
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormulas
basebook.Worksheets(wks.Name).Range("a1").PasteSpe cial Paste:=xlPasteFormats

'Next wks
mybook.Close savechanges:=False
Next N
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub
--
Your guidance is greatly appreciated!


"Dave Peterson" wrote:

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next


dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Import Worksheets and "Overright"

Instead of copying the worksheets, just copy the values and formulas (and
formats???).

You'll have to make sure that each worksheet exists in the receiving workbook,
but that seems reasonable if you already have charts that refer to data on those
sheets.


For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)
mybook.Close False
Next


dim wks as worksheet
....
for n = lbound(fname) to ubound(fname)
set mybook = workbooks.open(fname(n))
For each wks in mybook.worksheets
wks.cells.copy _
destination:=basebook.worksheets(wks.name).range(" a1")
'or
wks.cells.copy
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformulas
basebook.worksheets(wks.name).range("a1").pastespe cial paste:=xlpasteformats
next wks
mybook.close savechanges:=false
next n

(Untested, uncompiled. Watch for typos.)


Apprentice wrote:

I have this great code that imports worksheets into the active workbook. I
want the imported worksheets to overright the existing worksheets with the
same name. The imported and resident worksheets are all of the same name. I
don't want the imported worksheet to take the name of Worksheet (2.

The reason I'm doing this is because of charts that use the existing
referenced worksheets.

here is the code I have so far, all works fine except the (2):

Sub Import()
Dim basebook As Workbook
Dim mybook As Workbook
Dim N As Long
Dim MyPath As String
Dim SaveDriveDir As String
Dim FName As Variant

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings\eberger\My Documents\Employee
Survey\ES2009\NewWorkbooks\"
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),
*.xls", _
MultiSelect:=True)
If IsArray(FName) Then
Application.ScreenUpdating = False
Set basebook = ActiveWorkbook

For N = LBound(FName) To UBound(FName)
Set mybook = Workbooks.Open(FName(N))
mybook.Worksheets.Copy befo= _
basebook.Sheets(basebook.Sheets.Count)

mybook.Close False
Next
End If
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

--
Your guidance is greatly appreciated!


--

Dave Peterson
Reply
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
Excel formula for an "if" "then" scenario linking 3 worksheets John Excel Discussion (Misc queries) 2 February 23rd 10 06:56 PM
Import data "Hangs", A "time out" is needed. Help! :) John37309 Excel Programming 5 July 23rd 07 10:54 AM
Why is "History" a "reserved name" while naming Excel worksheets? Pradeep Excel Discussion (Misc queries) 1 June 30th 06 12:55 PM
Problem: Worksheets("New Style 2006").Unprotect Password:="naPrint" Karoo News[_2_] Excel Programming 1 January 30th 06 02:40 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM


All times are GMT +1. The time now is 10:14 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"