Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export data from vb.net to Excel, error: Select method of Range class failed

Posted on 2008-09-30
2
Medium Priority
?
907 Views
Last Modified: 2012-05-05
I'm currently making a vb.net program that will run several queries, and the results of each will automatically be put into worksheets in a new Excel workbook (i.e. one set of results will go into a new worksheet, the next set will go into a different worksheet, etc.).

I'm now trying to iterate though each of these worksheets and make formatting changes to them. The problem I'm having is related to Freezing Panes.  My original idea to perform the freeze was to manually select a cell in the row I want to freeze (i.e. Range("A8").select), and then use "Application.ActiveWindow.FreezePanes = true".  Whats interesting is that this does work, but only for the first worksheet in my workbook.  As soon as my program tries to select cell "A8" on any other sheet, it throws an error.

I've also tried doing this (oSheet is the current worksheet I'm iterating through):
"oSheet.Range("A8").Application.ActiveWindow.FreezePanes = true".

This doesn't throw an error (I'm not selecting a cell, technically), but it only freezes the panes on the first worksheet again. This is peculiar, because I am able to make other formatting changes (borders, fonts, change text in cells, page setups, etc.) to every other worksheet using my current method.


This is the code for applying the style changes to each worksheet (the applymacro function does all of the work). 
 
For counter = 0 To SheetTitles.Count - 1
    stdSheet = CType(xlSheets.Item(counter + 1), Excel.Worksheet)
    stdSheet.Name = SheetTitles((CountOfSheetsNeeded - 1) - counter)
    xlCells = stdSheet.Cells
    GenerateExcelFile(dsHolder((CountOfSheetsNeeded - 1) -counter).tables(0), xlCells) 'Fill in the data
    ApplyMacro(stdSheet)
 
Next
 
ApplyMacro header and line I'm getting an error on:
 
Private Sub ApplyMacro (ByVal oSheet as Excel.Worksheet)
   oSheet.Range("A8").Select()
End Sub

Open in new window

0
Comment
Question by:jacksonm1234
[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
2 Comments
 
LVL 2

Author Comment

by:jacksonm1234
ID: 22616953
Any help? Anyone? Anyone?
0
 
LVL 2

Accepted Solution

by:
jacksonm1234 earned 0 total points
ID: 22623815
I figured it out. All I had to do was call the Activate() method on each sheet I was iterating through.

Thanks to everyone who helped...oh wait....
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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