in reply to Adding pictures to Excel
Although VBA litters recorded macros with "Activate" and "Select", it's usually bad practice to let these leak into production code, as they slow the system down without doing anything useful. It's OK to use them to get the user where you want him when you finish, and there are certain situations where they can't be avoided. But if I were trying to put two pictures into an Excel sheet, my VBA would look like the following untested code:ActiveSheet.Pictures.Insert( _ "C:\Documents and Settings\All Users\Documents\My Pictures\Sam +ple Pictures\Blue hills.jpg" _ ).Select ActiveSheet.Pictures.Insert( _ "C:\Documents and Settings\All Users\Documents\My Pictures\Sam +ple Pictures\Sunset.jpg" _ ).Select Selection.ShapeRange.IncrementTop 290.25
From this, my first pass at Perl would be:Dim picCurrent As Picture Dim shtPics As Worksheet Set shtPics = ThisWorkbook.Sheets(1) Const ksPic1 As String = "C:\Documents and Settings\All Users\Document +s\My Pictures\Sample Pictures\Blue hills.jpg" Const ksPic2 As String = "C:\Documents and Settings\All Users\Document +s\My Pictures\Sample Pictures\Sunset.jpg" Set picCurrent = shtPics.Pictures.Insert(ksPic1) Set picCurrent = shtPics.Pictures.Insert(ksPic2) picCurrent.Top = 130 picCurrent.Left = 280
... and then I would start debugging. HTH, John Daviesuse strict; use warnings; use diagnostics; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->ActiveWorkbook; my $shtPics = $wb->Sheets(1); my $picCurrent = $shtPics->Pictures->Insert(first pic); $picCurrent = $shtPics->Pictures->Insert(second pic); $picCurrent->Top = 130; $picCurrent->Left = 280;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Adding pictures to Excel
by merrymonk (Hermit) on Jan 23, 2010 at 15:01 UTC | |
by merrymonk (Hermit) on Jan 23, 2010 at 15:24 UTC | |
by davies (Monsignor) on Jan 23, 2010 at 15:38 UTC | |
by merrymonk (Hermit) on Jan 23, 2010 at 16:01 UTC | |
by Anonymous Monk on Jan 24, 2010 at 04:09 UTC | |
Re^2: Adding pictures to Excel
by merrymonk (Hermit) on Jan 23, 2010 at 14:42 UTC | |
by davies (Monsignor) on Jan 23, 2010 at 15:11 UTC |