 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
CDK Guest
|
Posted: Tue Jan 20, 2004 9:34 am Post subject: Search/replace in Excel from my delphi program. |
|
|
Hi.
I need to be able to replace various strings in an excel document - as if I
had used the 'file->edit->search->replace command. I've created a macro in
and it's VBA source is as follows:
Cells.Replace What:="ptCPR", Replacement:="xxxxxx-xxxx", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Now I need to 'translate' this into delphi/pascal. So far my best guess has
been this:
V:=CreateOleObject('Excel.application');
V.Workbooks.Open(filnavn);
V.Cells.Replace(What:='ptCPR', Replacement:='xxxxxx-xxxx', LookAt:='xlPart',
_SearchOrder:='xlByRows', MatchCase:=False, SearchFormat:=False,
_ReplaceFormat:=False);
However, I get an "OLE error 800A03EC" when I try to do so. I am far from an
expert in the OLE world, so any help would be appreciated.
Does anyone know how to solve this one?
Best regards
Christian
(sorry for crossposting this to another newsgroup, but I had no idea which
one to use...)
|
|
| Back to top |
|
 |
Rick Carter Guest
|
Posted: Wed Jan 21, 2004 1:40 am Post subject: Re: Search/replace in Excel from my delphi program. |
|
|
I have no experience with this, but if nobody jumps in here to help, I'll
tell you you'll most likely find the answer in the group
borland.public.delphi.oleautomation -- if you're not set up to post
directly to the Borland groups, you can read and post from
http://newsgroups.borland.com/
You're also likely to find some good resources on the home page of Deborah Pate,
who posts regularly to that group.
Rick Carter
Chair, Paradox/Delphi SIG, Cincinnati PC Users Group
|
|
| Back to top |
|
 |
AlanGLLoyd Guest
|
Posted: Wed Jan 21, 2004 8:48 am Post subject: Re: Search/replace in Excel from my delphi program. |
|
|
In article <400cf623$0$140$edfadb0f (AT) dread11 (DOT) news.tele.dk>, "CDK"
<kriller (AT) NOSPAMsofthome (DOT) net> writes:
| Quote: | V:=CreateOleObject('Excel.application');
V.Workbooks.Open(filnavn);
V.Cells.Replace(What:='ptCPR', Replacement:='xxxxxx-xxxx', LookAt:='xlPart',
_SearchOrder:='xlByRows', MatchCase:=False, SearchFormat:=False,
_ReplaceFormat:=False);
|
I'm no expert but if you have not yet got an answer I would start by trying ...
1 Which line causes the error.
2 Remove the underlines - these are VB line extension characters
3 I think that the bracketed part is a character array, containing strings,
which is interpreted by Excel Basic. Basic expects strings to be surrounded by
doublequotes. I would try ...
Replace('What:="' + ptCPR + '", Replacement:="xxxxxx-xxxx", LookAt:=xlPart,' +,
'SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,' +
'ReplaceFormat:=False');
.... this assumes that ptCPR is a Delphi variable (otherwise replace "' + ptCPR
+'" with "ptCPR"). Note that xlPart, xlByRows & False are VB constants and so,
while part of the delphi string, are not VB strings and should not have
surrounding double quotes.
Alan Lloyd
[email]alanglloyd (AT) aol (DOT) com[/email]
|
|
| Back to top |
|
 |
CDK Guest
|
Posted: Wed Jan 21, 2004 10:34 am Post subject: Re: Search/replace in Excel from my delphi program. |
|
|
Thanks for your reply - I think you've guided me in the right direction,
however my troubles are not over yet.
I'm getting another error now complaining about variable types - This should
be easier to fix than the ugly 'noname' OLE error from before.
I will look into this and get back - either with an answer to my problems or
another question ;-)
Thanks again
Christian.
(btw: 'ptCPR' wasn't a variable but a string - CPR is the Danish equivalent
of SSN in the US)
"AlanGLLoyd" <alanglloyd (AT) aol (DOT) com> skrev i en meddelelse
news:20040121034852.21955.00000100 (AT) mb-m20 (DOT) aol.com...
| Quote: | In article <400cf623$0$140$edfadb0f (AT) dread11 (DOT) news.tele.dk>, "CDK"
[email]kriller (AT) NOSPAMsofthome (DOT) net[/email]> writes:
V:=CreateOleObject('Excel.application');
V.Workbooks.Open(filnavn);
V.Cells.Replace(What:='ptCPR', Replacement:='xxxxxx-xxxx',
LookAt:='xlPart',
_SearchOrder:='xlByRows', MatchCase:=False, SearchFormat:=False,
_ReplaceFormat:=False);
I'm no expert but if you have not yet got an answer I would start by
trying ...
1 Which line causes the error.
2 Remove the underlines - these are VB line extension characters
3 I think that the bracketed part is a character array, containing
strings,
which is interpreted by Excel Basic. Basic expects strings to be
surrounded by
doublequotes. I would try ...
Replace('What:="' + ptCPR + '", Replacement:="xxxxxx-xxxx",
LookAt:=xlPart,' +,
'SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,' +
'ReplaceFormat:=False');
... this assumes that ptCPR is a Delphi variable (otherwise replace "' +
ptCPR
+'" with "ptCPR"). Note that xlPart, xlByRows & False are VB constants and
so,
while part of the delphi string, are not VB strings and should not have
surrounding double quotes.
Alan Lloyd
[email]alanglloyd (AT) aol (DOT) com[/email]
|
|
|
| Back to top |
|
 |
Macmidas Guest
|
Posted: Wed Jan 19, 2005 4:20 am Post subject: Re: Search/replace in Excel from my delphi program. |
|
|
I'm seeing the exact same problem and it's happening on the Workbooks.Open
line in my program. At first I wasn't able to recreate the error on my
machine (though it happens every time on my customer's machine, of
course). I used the single explicit parameter for the file name (like
you) and trusted the default paramters to work.
I started replacing parameters one at a time and discovered that adding
"EmptyParam" in the fourth parameter (Format) caused the same error to
appear on my machine.
I'm wondering if the problem is that I have Excel2003 on my machine and my
customer has Excel2000. I'm not sure what version of Excel the originator
of the file is using.
Has anybody learned anything else about this problem?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|