Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic and Excel

Status
Not open for further replies.

schnabs

Technical User
Jan 21, 2009
50
I am using Visual Basic 08 Express to open and excel workbook, refresh the ODBC queries in it, and save and close it. I have not added the code for the save and close yet, but my question is two fold.
First, my workbook has one sheet with 80 or so queries. When I ran my code, it opened the file and refreshed the queries, but it throws an error on some of them. It still seems random which ones error out, and when I refresh the queries individually without VB, they work fine. So is there a way to refresh all the queries on the one sheet?
If not, then I wanted to put each query on it's own sheet, refresh each and move on to the next sheet, combining everything in one main sheet. I cannot seem to come up with the code necessary to open sheet, refresh save, move on to next sheet in the same workbook. Here is my code for you to look at .

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oxl As Microsoft.Office.Interop.Excel.Application
Dim i#

oxl = New Microsoft.Office.Interop.Excel.Application
oxl.Visible = True
oxl.Workbooks.Open("Z:\test_alpha by property.xls")
oxl.ActiveWorkbook.RefreshAll()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Thanks in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top