Solved

VisualBasical 2010 w/Excel 2007

Posted on 2012-04-04
6
204 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

820 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