Solved

VisualBasical 2010 w/Excel 2007

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
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 will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

809 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