A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Error Doing For Each ws



 
 
Thread Tools Display Modes
  #1  
Old January 14th, 2006, 10:18 AM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Error Doing For Each ws

Here's the problem I'm having with the code below.

If the worksheet contains no query-table the codes exits the inner loop
(For Each qt) and moves to the next worksheet with no error.

However, when the worksheet does contains a query-table the code exits
the inner loop but fails when it hits the 'Next ws'.
At that point it returns a "'Run-time error '13': type mismatch". If I
choose debug and then resume the codes continues until it encounters
the next sheet with a query-table.

Any advice will be appreciated
Buck
================================================== ===

Dim ws As Worksheet
Dim wsName As String
Dim pt As PivotTable
Dim ptname As String
Dim qt As QueryTable
Dim qtname As String

'Loop through all sheets and updates all QueryTables
Set wb = ActiveWorkbook
For Each ws In wb.Sheets
wsName = ws.Name
For Each qt In ws.QueryTables
qtname = qt.Name
Worksheets(wsName).Activate
Range("A1").Activate
Worksheets(wsName).QueryTables(qtname).Refresh
BackgroundQuery:=False
Next qt
Else
End If
Next ws

  #2  
Old January 14th, 2006, 12:13 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Error Doing For Each ws

I'd suggest asking this in a newsgroup related to Excel.

This newsgroup is for questions about Access, the database product that's
part of Office Professional.

However, what you've posted can't possibly be your actual code, since you've
got two lines:
Else
End If

before your "Next ws" statement, and there's no If statement anywhere.


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


" wrote in message
ups.com...
Here's the problem I'm having with the code below.

If the worksheet contains no query-table the codes exits the inner loop
(For Each qt) and moves to the next worksheet with no error.

However, when the worksheet does contains a query-table the code exits
the inner loop but fails when it hits the 'Next ws'.
At that point it returns a "'Run-time error '13': type mismatch". If I
choose debug and then resume the codes continues until it encounters
the next sheet with a query-table.

Any advice will be appreciated
Buck
================================================== ===

Dim ws As Worksheet
Dim wsName As String
Dim pt As PivotTable
Dim ptname As String
Dim qt As QueryTable
Dim qtname As String

'Loop through all sheets and updates all QueryTables
Set wb = ActiveWorkbook
For Each ws In wb.Sheets
wsName = ws.Name
For Each qt In ws.QueryTables
qtname = qt.Name
Worksheets(wsName).Activate
Range("A1").Activate
Worksheets(wsName).QueryTables(qtname).Refresh
BackgroundQuery:=False
Next qt
Else
End If
Next ws



  #3  
Old January 14th, 2006, 12:24 PM posted to microsoft.public.access
external usenet poster
 
Posts: n/a
Default Error Doing For Each ws

It looks like Excel VBA code so I suggest you re-post the question in one of
the relevant newsgroups for Excel.

This newsgroup is for Microsoft Access, a database application, and not
general computer "access".

--
HTH
Van T. Dinh
MVP (Access)



" wrote in message
ups.com...
Here's the problem I'm having with the code below.

If the worksheet contains no query-table the codes exits the inner loop
(For Each qt) and moves to the next worksheet with no error.

However, when the worksheet does contains a query-table the code exits
the inner loop but fails when it hits the 'Next ws'.
At that point it returns a "'Run-time error '13': type mismatch". If I
choose debug and then resume the codes continues until it encounters
the next sheet with a query-table.

Any advice will be appreciated
Buck
================================================== ===

Dim ws As Worksheet
Dim wsName As String
Dim pt As PivotTable
Dim ptname As String
Dim qt As QueryTable
Dim qtname As String

'Loop through all sheets and updates all QueryTables
Set wb = ActiveWorkbook
For Each ws In wb.Sheets
wsName = ws.Name
For Each qt In ws.QueryTables
qtname = qt.Name
Worksheets(wsName).Activate
Range("A1").Activate
Worksheets(wsName).QueryTables(qtname).Refresh
BackgroundQuery:=False
Next qt
Else
End If
Next ws



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.