[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

cannot convert oleobject in any variable to integer

Posted on 2007-10-17
3
Medium Priority
?
1,764 Views
Last Modified: 2013-12-26
Greetings All,

I have some powerbuilder code that opens a spreadsheet and writes out some information.  My problem is that I want to add additional sheets in Excel and then make them active.  The example code that I have seen always uses a number to refer to a spreadsheet as follows:

xlsub = xlapp.Application.ActiveWorkbook.Worksheets[1]

That works fine.  But now I am trying to substitute the number '1' for a variable called newsheet.  I am getting an 'ANY' / 'LONG' conversion error.

Here is my code:

//now add additional sheets and rename the tabs to coincide with the voucher number
any newsheet
string voucher
      For r = 1 to numrows
            voucher = trim(dw_2.getitemstring(r, "voucher_no"))

      if not isnull(voucher) then
            newsheet = xlapp.Application.ActiveWorkbook.Worksheets.add()
            xlsub = xlapp.Application.ActiveWorkbook.Worksheets[newsheet]
            xlapp.Application.ActiveWorkbook.Worksheets[newsheet].name(voucher)
      end if
      next

Any help would really, really be appreciated...

Thanks!

Paul
0
Comment
Question by:pemurray
  • 2
3 Comments
 

Author Comment

by:pemurray
ID: 20094926
One more thing, please...

I can add a sheet, but it adds it before another sheet.  I want it to add after.

I have tried a variety of things, none of which work...

newsheet = xlapp.Application.ActiveWorkbook.Worksheets.add(after)
newsheet = xlapp.Application.ActiveWorkbook.Worksheets.add([after])
newsheet = xlapp.Application.ActiveWorkbook.Worksheets.add("after")
newsheet = xlapp.Application.ActiveWorkbook.Worksheets.add(["after"])

Is there a cookbook somewhere that tells how to translate the examples for Excel to PowerBuilder?
0
 
LVL 18

Expert Comment

by:diasroshan
ID: 20098951
Hi,

Replace,
any newsheet
with,
OleObject newsheet


Cheers,
Rosh
0
 
LVL 18

Accepted Solution

by:
diasroshan earned 2000 total points
ID: 20098972
Hi,

just an example to enhace ur code to ADD TO LAST worksheet

OleObject newsheet
string voucher
Long i = 0
      For r = 1 to numrows
            voucher = trim(dw_2.getitemstring(r, "voucher_no"))

      if not isnull(voucher) then
            i++
            newsheet = xlapp.Application.ActiveWorkbook.Worksheets.add()
            xlsub = xlapp.Application.ActiveWorkbook.Worksheets[i]
            xlapp.Application.ActiveWorkbook.Worksheets[i].name(voucher)
      end if
      next

Try the above code... i havent tried it... we can work on it...

Cheers,
Rosh
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question