Page 1 of 1
Ms-Excel code to FWH
Posted: Wed May 14, 2008 7:57 pm
by Jeff Barnes
Hi Everybody,
Can someone please help me convert this to FWH.
Code: Select all
Sub InsertPicture()
Dim oSheet As Worksheet
Dim cBMP1 As String
Dim cBMP2 As String
Dim rngOutput As Range
Set oSheet = ActiveSheet
cBMP1 = "C:\temp\a.bmp"
Set rngOutput = oSheet.Range("A1", "A1")
With oSheet.Pictures.Insert(cBMP1)
.Left = rngOutput.Left
.Top = rngOutput.Top
End With
cBMP2 = "C:\temp\b.bmp"
Set rngOutput = oSheet.Range("A61", "A61")
With oSheet.Pictures.Insert(cBMP2)
.Left = rngOutput.Left
.Top = rngOutput.Top
End With
End Sub
The area I'm most stuck with is:
Code: Select all
With oSheet.Pictures.Insert(cBMP2)
.Left = rngOutput.Left
.Top = rngOutput.Top
End With
Re: Ms-Excel code to FWH
Posted: Thu May 15, 2008 7:16 am
by Enrico Maria Giordano
Jeff Barnes wrote:The area I'm most stuck with is:
Code: Select all
With oSheet.Pictures.Insert(cBMP2)
.Left = rngOutput.Left
.Top = rngOutput.Top
End With
Code: Select all
WITH oSheet:Pictures:Insert(cBMP2)
:Left = rngOutput:Left
:Top = rngOutput:Top
END
EMG
Posted: Fri May 16, 2008 2:25 pm
by Jeff Barnes
I need a bit more help with this one...
I try to use the code:
Code: Select all
rngOutput := oSheet:Range("A1","A1")
oSheet:Pictures:Insert(cLogo)
WITH
:Left = rngOutput:Left
:Top = rngOutput:Top
END
But I get the following errors when I compile...
Compiling...
xHarbour Compiler build 0.99.71 (SimpLex)
Copyright 1999-2007,
http://www.xharbour.org http://www.harbour-project.org/
Compiling 'EzSat.prg' and generating preprocessed output to 'EzSat.ppo'...
EzSat.prg(5714) Error E0030 Syntax error: "parse error at 'OSHEET'"
EzSat.prg(5715) Error E0054 WITH Message [LEFT] with no WITH OBJECT in sight.
EzSat.prg(5716) Error E0054 WITH Message [TOP] with no WITH OBJECT in sight.
EzSat.prg(5721) Error E0010 ENDIF does not match IF
4 errors
No code generated
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
EzSat.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
* Application successfully built
Any ideas?
Posted: Fri May 16, 2008 2:28 pm
by Jeff Barnes
There was a typo ... the code giving me the error is:
Code: Select all
rngOutput := oSheet:Range("A1","A1")
WITH oSheet:Pictures:Insert(cLogo)
:Left = rngOutput:Left
:Top = rngOutput:Top
END
And the error is:
Compiling...
xHarbour Compiler build 0.99.71 (SimpLex)
Copyright 1999-2007,
http://www.xharbour.org http://www.harbour-project.org/
Compiling 'EzSat.prg' and generating preprocessed output to 'EzSat.ppo'...
EzSat.prg(5714) Error E0030 Syntax error: "parse error at 'OSHEET'"
EzSat.prg(5715) Error E0054 WITH Message [LEFT] with no WITH OBJECT in sight.
EzSat.prg(5716) Error E0054 WITH Message [TOP] with no WITH OBJECT in sight.
EzSat.prg(5721) Error E0010 ENDIF does not match IF
4 errors
No code generated
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
EzSat.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
* Application successfully built
Posted: Fri May 16, 2008 2:58 pm
by mmercado
Hi Jeff:
Just guessing:
Code: Select all
oSheet:Pictures:Insert(cBMP2):Left = rngOutput.Left
oSheet:Pictures:Insert(cBMP2):Top = rngOutput.Top
or
oPict := oSheet:Pictures:Insert(cBMP2)
oPict:Left = rngOutput.Left
oPict:Top = rngOutput.Top
Regards
Manuel Mercado
Posted: Fri May 16, 2008 3:00 pm
by Enrico Maria Giordano
There are no errors in the portion of code you reported.
EMG
Posted: Fri May 16, 2008 7:14 pm
by Jeff Barnes
I've tried Manuel and Enrico's examples with no luck.
I made a small test program to make it easier.
Code: Select all
#Include "Fivewin.ch"
Function Main()
Local oExcel, oSheet, rngOutput, cLogo:="\EzSat\Logo.bmp"
oExcel := TOleAuto():New( "Excel.Application" )
oSheet := oExcel:Get("ActiveSheet")
oExcel:Set( "DisplayAlerts", .T.)
oExcel:Set( "Visible", .T.)
rngOutput := oSheet:Range("A1","A1")
WITH oSheet:Pictures:Insert(cLogo)
:Left=rngOutput:Left
:Top=rngOutput:Top
END
Return Nil
When I compile the above code I get the following error when I compile the program:
Compiling...
xHarbour Compiler build 0.99.71 (SimpLex)
Copyright 1999-2007,
http://www.xharbour.org http://www.harbour-project.org/
Compiling 'testexcel.prg' and generating preprocessed output to 'testexcel.ppo'.
..
testexcel.prg(12) Error E0030 Syntax error: "parse error at 'OSHEET'"
testexcel.prg(13) Error E0054 WITH Message [LEFT] with no WITH OBJECT in sight.
testexcel.prg(14) Error E0054 WITH Message [TOP] with no WITH OBJECT in sight.
testexcel.prg(15) Error E0030 Syntax error: "parse error at 'END'"
4 errors
No code generated
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Error E2194: Could not find file 'testexcel.c'
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Fatal: Unable to open file 'TESTEXCEL.OBJ'
* There are errors
Can anyone see where I am going wrong? Am I leaving something out?
Posted: Sat May 17, 2008 12:38 am
by mmercado
Hi Jeff:
Here you are a similar working sample:
Code: Select all
#include "fivewin.ch"
Function Main()
Local oWnd, oMenu
MENU oMenu
MENUITEM "Picture to Excel" ACTION XlsImage( "\FWH\BitMaps\Cara.bmp" )
MENUITEM "Exit" ACTION oWnd:End()
ENDMENU
DEFINE WINDOW oWnd MENU oMenu
Activate WINDOW oWnd MAXIMIZED
Return Nil
Static Function XlsImage( cFile )
Local oExcel, oSheet, oImg
oExcel := TOleAuto():New("Excel.Application")
oExcel:WorkBooks:Add()
oSheet := oExcel:Get( "ActiveSheet" )
oSheet:Range( "B5:B5" ):Select()
oImg := oSheet:Pictures:Insert( cFile )
oImg:Select()
oExcel:Visible := .T.
OleUninitialize()
Return Nil
Regards.
Manuel Mercado
Posted: Sat May 17, 2008 2:50 am
by Jeff Barnes
Hi Manuel,
Your method is basically the way I normally insert an image.
The problem I am having is that Excel 2007 works differently than previous versions of Excel.
When I use the code in your example with 2007 the images do not go into the selected cells.
I went on an Excel newsgroup and it was suggested that I do it the following way:
(
http://www.excelforum.com/showthread.ph ... ost1917614)
Code: Select all
Sub InsertPicture()
Dim oSheet As Worksheet
Dim cBMP1 As String
Dim cBMP2 As String
Dim rngOutput As Range
Set oSheet = ActiveSheet
cBMP1 = "C:\temp\a.bmp"
Set rngOutput = oSheet.Range("A1", "A1")
With oSheet.Pictures.Insert(cBMP1)
.Left = rngOutput.Left
.Top = rngOutput.Top
End With
cBMP2 = "C:\temp\b.bmp"
Set rngOutput = oSheet.Range("A61", "A61")
With oSheet.Pictures.Insert(cBMP2)
.Left = rngOutput.Left
.Top = rngOutput.Top
End With
End Sub
So I am trying to convert this code to FWH so I can insert the images using Excel 2007.
[/url]
Posted: Sat May 17, 2008 12:34 pm
by Enrico Maria Giordano
Jeff Barnes wrote:I've tried Manuel and Enrico's examples with no luck.
I made a small test program to make it easier.
Now I see the error. Replace
Code: Select all
WITH oSheet:Pictures:Insert(cLogo)
with
Code: Select all
WITH OBJECT oSheet:Pictures:Insert(cLogo)
EMG
Posted: Sun May 18, 2008 10:49 pm
by Jeff Barnes
It is working Now.
Thanks once again