Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VisualBasical 2010 w/Excel 2007

Posted on 2012-04-04
6
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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.

719 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