Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VisualBasical 2010 w/Excel 2007

Posted on 2012-04-04
6
Medium Priority
?
209 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 2000 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 36

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

971 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