Solved

VisualBasical 2010 w/Excel 2007

Posted on 2012-04-04
6
201 Views
Last Modified: 2013-07-23
Hi All,

I have a visual basic program that copies data from a text file puts it in a worksheet and makes a graph from the data.  For some reason the exe works fine on my machine but does not well on another.

Particularly it is failing on:
metricWorkbook.Worksheets(filename).copy(after:=XLSXWorkbook.Worksheets("Sheet1"))
        XLSXWorkbook.ActiveSheet.Name = MetricType


MetricType is defined as "PSNR"
filename as "DL1"

The issue is it works fine on all other machines except this one.  I do not see any dependencies except .net 4.0 which is installed. :(
0
Comment
Question by:ilcapocamorra
  • 2
6 Comments
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 37808049
Is there possibly no "Sheet1"?  Probably not a good idea to hardcode that value in there.  If it's the first worksheet you should use the index (1).  If it's a worksheet other than a newly created workbook, or you don't for sure know it's the first (left-most) worksheet you want to work with, you should probably set the worksheet as a variable first.

Regards,
Zack Barresse
0
 

Author Comment

by:ilcapocamorra
ID: 37809809
Hi Zack, thanks for the feedback, so something like:

metricWorkbook.Worksheets(filename).copy(after:=XLSXWorkbook.Worksheets(index(1)))

Thanks!
0
 
LVL 14

Accepted Solution

by:
Zack Barresse earned 500 total points
ID: 37812816
Almost, like this:

metricWorkbook.Worksheets(filename).copy(after:=XLSXWorkbook.Worksheets(1))

Open in new window


It's the index property of the Worksheets object.  It's just tough to assume the sheet name will always be "Sheet1".  But it may also, circumstances depending, difficult to assume it will always be the first sheet in the workbook.  If you want to copy it after the first sheet, use the index of 1.  If you want to copy it after the last sheet, use the Count property of the Worksheets object...

metricWorkbook.Worksheets(filename).copy(after:=XLSXWorkbook.Worksheets(XLSXWorkbook.Worksheets.Count))

Open in new window


... which will put it as the last worksheet in the "XLSXWorkbook" object.

HTH

Regards,
Zack
0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 37817820
it seems to be an environmental issue:
Does the target machine has Excel 2007 installed?
If so:
Are the Excel 2007 service pack/updates the same on all machines?
How are you interfacing to Excel? (Interop, open xml)
Is th user opening the target workbook?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now