Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Adapt code to copy out pictures as well

I've got the following code which exports all sheets containing charts to a
new workbook. Each sheet name is also copied across, as well as all summary
information.

I've now added 8 logo's onto each source sheet, therefore in the process of
copying out the chart sheets, I'd like to be able to copy the new pictures
(inc. the size, position, etc) as well.

Any ideas as to how I might be able to do this?

=================

Sub CopyChart()
Dim ChartBook As Workbook, SourceBook As Workbook
Dim TmpSheets As Integer, wkSheet As Worksheet
Dim ChartObj, ChartCount As Long

Set SourceBook = ActiveWorkbook

For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count 0 Then
ChartCount = ChartCount + 1
End If
Next

If ChartCount < 1 Then Exit Sub

TmpSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = ChartCount
Set ChartBook = Workbooks.Add
Application.SheetsInNewWorkbook = TmpSheets
TmpSheets = 1

For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count 0 Then
With ChartBook.Sheets(TmpSheets)
.Activate
.Name = wkSheet.Name
wkSheet.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.Cells.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
'.Paste
'.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
.ChartObjects.Delete
End With
ChartCount = 1
For Each ChartObj In wkSheet.ChartObjects
ChartObj.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChartBook.Sheets(TmpSheets) _
.PasteSpecial Format:="Picture (Enhanced Metafile)", _
Link:=False, DisplayAsIcon:=False
With ChartBook.Sheets(TmpSheets).Shapes(ChartCount)
.Top = ChartObj.Top
.Left = ChartObj.Left
End With
ChartCount = ChartCount + 1
Next
TmpSheets = TmpSheets + 1
End If
Range("A1").Select
Next

End Sub
==================
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Adapt code to copy out pictures as well

Just a thought here - to reduce code and make it more manageable, would it be
better to Save As and then remove the content that you don't want to retain
from there?

"Sarah (OGI)" wrote:

I've got the following code which exports all sheets containing charts to a
new workbook. Each sheet name is also copied across, as well as all summary
information.

I've now added 8 logo's onto each source sheet, therefore in the process of
copying out the chart sheets, I'd like to be able to copy the new pictures
(inc. the size, position, etc) as well.

Any ideas as to how I might be able to do this?

=================

Sub CopyChart()
Dim ChartBook As Workbook, SourceBook As Workbook
Dim TmpSheets As Integer, wkSheet As Worksheet
Dim ChartObj, ChartCount As Long

Set SourceBook = ActiveWorkbook

For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count 0 Then
ChartCount = ChartCount + 1
End If
Next

If ChartCount < 1 Then Exit Sub

TmpSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = ChartCount
Set ChartBook = Workbooks.Add
Application.SheetsInNewWorkbook = TmpSheets
TmpSheets = 1

For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count 0 Then
With ChartBook.Sheets(TmpSheets)
.Activate
.Name = wkSheet.Name
wkSheet.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.Cells.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
'.Paste
'.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
.ChartObjects.Delete
End With
ChartCount = 1
For Each ChartObj In wkSheet.ChartObjects
ChartObj.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChartBook.Sheets(TmpSheets) _
.PasteSpecial Format:="Picture (Enhanced Metafile)", _
Link:=False, DisplayAsIcon:=False
With ChartBook.Sheets(TmpSheets).Shapes(ChartCount)
.Top = ChartObj.Top
.Left = ChartObj.Left
End With
ChartCount = ChartCount + 1
Next
TmpSheets = TmpSheets + 1
End If
Range("A1").Select
Next

End Sub
==================

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adapt code to copy out pictures as well

I'd add a line to this code that would do the picture copying:

....
Call CopyAllPictures

End sub

You have a response to your picture post.

Sarah (OGI) wrote:

I've got the following code which exports all sheets containing charts to a
new workbook. Each sheet name is also copied across, as well as all summary
information.

I've now added 8 logo's onto each source sheet, therefore in the process of
copying out the chart sheets, I'd like to be able to copy the new pictures
(inc. the size, position, etc) as well.

Any ideas as to how I might be able to do this?

=================

Sub CopyChart()
Dim ChartBook As Workbook, SourceBook As Workbook
Dim TmpSheets As Integer, wkSheet As Worksheet
Dim ChartObj, ChartCount As Long

Set SourceBook = ActiveWorkbook

For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count 0 Then
ChartCount = ChartCount + 1
End If
Next

If ChartCount < 1 Then Exit Sub

TmpSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = ChartCount
Set ChartBook = Workbooks.Add
Application.SheetsInNewWorkbook = TmpSheets
TmpSheets = 1

For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count 0 Then
With ChartBook.Sheets(TmpSheets)
.Activate
.Name = wkSheet.Name
wkSheet.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.Cells.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
'.Paste
'.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
.ChartObjects.Delete
End With
ChartCount = 1
For Each ChartObj In wkSheet.ChartObjects
ChartObj.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChartBook.Sheets(TmpSheets) _
.PasteSpecial Format:="Picture (Enhanced Metafile)", _
Link:=False, DisplayAsIcon:=False
With ChartBook.Sheets(TmpSheets).Shapes(ChartCount)
.Top = ChartObj.Top
.Left = ChartObj.Left
End With
ChartCount = ChartCount + 1
Next
TmpSheets = TmpSheets + 1
End If
Range("A1").Select
Next

End Sub
==================


--

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
Adapt code to show filter Jack Excel Programming 2 January 19th 06 11:22 AM
Adapt code to loop through sheets Stuart[_21_] Excel Programming 3 October 7th 05 02:28 AM
Using Find/Replace in Visual basic to adapt the code Zakynthos Excel Programming 6 September 8th 05 03:41 PM
code for pictures in comments steve Excel Programming 2 June 14th 05 02:29 PM
Please help me to adapt this code. Rob Hargreaves Excel Programming 1 February 2nd 05 08:27 PM


All times are GMT +1. The time now is 06:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"