PC Review


Reply
Thread Tools Rate Thread

copying the objects from a sheet

 
 
Michelle
Guest
Posts: n/a
 
      12th May 2010
I am trying to write code to copy the objects (logos, graphics, etc) from
one sheet to another, and have them come up in the same place on the
destination sheet.

At the moment, it's putting them somewhere near but not quite at the top of
the sheet and shifting them left a bit

Is there a way to get them to go in the same place?

Here's the code that isn't working:
Sheets("Sheet1").Select
ActiveSheet.DrawingObjects.Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.PasteSpecial Format:="MS Office Drawing Object",
Link:=False, _
DisplayAsIcon:=False
'=====================

Thanks

M

 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      12th May 2010
Things work slightly differently in 97-2003 and later versions. This isn't
optimal for either but should work in both (but note the ActiveX caveat)

Sub test1()
Dim i As Long, j As Long, first As Long
Dim sAddr As String
Dim shtOrig As Object
Dim dwOb As Object
Dim dwObs As Object

' don't use this if ActiveX controls being copied

Set dwObs = Worksheets("Sheet1").DrawingObjects
If dwObs.Count = 0 Then Exit Sub

dwObs.Copy

Worksheets("Sheet2").Paste

With Worksheets("Sheet2").DrawingObjects

For i = .Count - dwObs.Count + 1 To .Count
j = j + 1
With .Item(i)
.Left = dwObs(j).Left
.Top = dwObs(j).Top
End With
Next

End With

' optional deselect the objects
' Worksheets("Sheet2").Activate
' ActiveCell.Select

End Sub

Regards,
Peter T


"Michelle" <(E-Mail Removed)> wrote in message
news:F28F291E-9806-4B6D-A34E-(E-Mail Removed)...
>I am trying to write code to copy the objects (logos, graphics, etc) from
>one sheet to another, and have them come up in the same place on the
>destination sheet.
>
> At the moment, it's putting them somewhere near but not quite at the top
> of the sheet and shifting them left a bit
>
> Is there a way to get them to go in the same place?
>
> Here's the code that isn't working:
> Sheets("Sheet1").Select
> ActiveSheet.DrawingObjects.Select
> Selection.Copy
> Sheets("Sheet2").Select
> ActiveSheet.PasteSpecial Format:="MS Office Drawing Object",
> Link:=False, _
> DisplayAsIcon:=False
> '=====================
>
> Thanks
>
> M



 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      13th May 2010
Peter - that is BRILLIANT!

Thank you

M


"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> Things work slightly differently in 97-2003 and later versions. This isn't
> optimal for either but should work in both (but note the ActiveX caveat)
>
> Sub test1()
> Dim i As Long, j As Long, first As Long
> Dim sAddr As String
> Dim shtOrig As Object
> Dim dwOb As Object
> Dim dwObs As Object
>
> ' don't use this if ActiveX controls being copied
>
> Set dwObs = Worksheets("Sheet1").DrawingObjects
> If dwObs.Count = 0 Then Exit Sub
>
> dwObs.Copy
>
> Worksheets("Sheet2").Paste
>
> With Worksheets("Sheet2").DrawingObjects
>
> For i = .Count - dwObs.Count + 1 To .Count
> j = j + 1
> With .Item(i)
> .Left = dwObs(j).Left
> .Top = dwObs(j).Top
> End With
> Next
>
> End With
>
> ' optional deselect the objects
> ' Worksheets("Sheet2").Activate
> ' ActiveCell.Select
>
> End Sub
>
> Regards,
> Peter T
>
>
> "Michelle" <(E-Mail Removed)> wrote in message
> news:F28F291E-9806-4B6D-A34E-(E-Mail Removed)...
>>I am trying to write code to copy the objects (logos, graphics, etc) from
>>one sheet to another, and have them come up in the same place on the
>>destination sheet.
>>
>> At the moment, it's putting them somewhere near but not quite at the top
>> of the sheet and shifting them left a bit
>>
>> Is there a way to get them to go in the same place?
>>
>> Here's the code that isn't working:
>> Sheets("Sheet1").Select
>> ActiveSheet.DrawingObjects.Select
>> Selection.Copy
>> Sheets("Sheet2").Select
>> ActiveSheet.PasteSpecial Format:="MS Office Drawing Object",
>> Link:=False, _
>> DisplayAsIcon:=False
>> '=====================
>>
>> Thanks
>>
>> M

>
>


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      13th May 2010
That's nice, glad it worked :-)

I see there are some unused variable declarations you can get rid of (that
I'd used in earlier testing)

Regards,
Peter T


"Michelle" <(E-Mail Removed)> wrote in message
news:2B2DFFB9-2DAD-4851-80F6-(E-Mail Removed)...
> Peter - that is BRILLIANT!
>
> Thank you
>
> M
>
>
> "Peter T" <peter_t@discussions> wrote in message
> news:(E-Mail Removed)...
>> Things work slightly differently in 97-2003 and later versions. This
>> isn't optimal for either but should work in both (but note the ActiveX
>> caveat)
>>
>> Sub test1()
>> Dim i As Long, j As Long, first As Long
>> Dim sAddr As String
>> Dim shtOrig As Object
>> Dim dwOb As Object
>> Dim dwObs As Object
>>
>> ' don't use this if ActiveX controls being copied
>>
>> Set dwObs = Worksheets("Sheet1").DrawingObjects
>> If dwObs.Count = 0 Then Exit Sub
>>
>> dwObs.Copy
>>
>> Worksheets("Sheet2").Paste
>>
>> With Worksheets("Sheet2").DrawingObjects
>>
>> For i = .Count - dwObs.Count + 1 To .Count
>> j = j + 1
>> With .Item(i)
>> .Left = dwObs(j).Left
>> .Top = dwObs(j).Top
>> End With
>> Next
>>
>> End With
>>
>> ' optional deselect the objects
>> ' Worksheets("Sheet2").Activate
>> ' ActiveCell.Select
>>
>> End Sub
>>
>> Regards,
>> Peter T
>>
>>
>> "Michelle" <(E-Mail Removed)> wrote in message
>> news:F28F291E-9806-4B6D-A34E-(E-Mail Removed)...
>>>I am trying to write code to copy the objects (logos, graphics, etc) from
>>>one sheet to another, and have them come up in the same place on the
>>>destination sheet.
>>>
>>> At the moment, it's putting them somewhere near but not quite at the top
>>> of the sheet and shifting them left a bit
>>>
>>> Is there a way to get them to go in the same place?
>>>
>>> Here's the code that isn't working:
>>> Sheets("Sheet1").Select
>>> ActiveSheet.DrawingObjects.Select
>>> Selection.Copy
>>> Sheets("Sheet2").Select
>>> ActiveSheet.PasteSpecial Format:="MS Office Drawing Object",
>>> Link:=False, _
>>> DisplayAsIcon:=False
>>> '=====================
>>>
>>> Thanks
>>>
>>> M

>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying objects to new sheet failure =?Utf-8?B?U3RldmVu?= Microsoft Excel Misc 0 25th Jul 2007 02:50 PM
copying an arraylist of objects into an array of the objects themselves. hazz Microsoft C# .NET 5 18th Nov 2005 04:19 PM
Copying cells from on sheet to another sheet (via sheet module) =?Utf-8?B?Q1JheUY=?= Microsoft Excel Programming 6 20th Sep 2005 08:58 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian Microsoft Excel Programming 1 26th Aug 2004 10:49 PM
cannot shift objects off sheet, but also cannot find objects danielo Microsoft Excel Misc 6 5th Aug 2004 09:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:25 AM.