For Each Table...

Ragnar78

Board Regular
Joined
Feb 10, 2004
Messages
210
Hy,

How can i use the FOR EACH to remove all the tables i have...

Code:
For Each Table in ...

If Table.name <> "indexes" the
Table.delete
End if

Next

indexes is the only table i dont want to remove, but i dont know what collection to call to set Table in...
Tx for the help
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try

dim db
dim tb

set db = CurrentDb

for each tb in db.TableDefs

If tb.Name <> "indexes" then

db.TableDefs.delete tb.name

End If

next
 
Upvote 0
Don't forget about the system tables you're about to delete as it works through the full table list. A few of the selections would be:

MSysACEs
MSysObjects
MSysQueries
MSysRelationships

One method is to exclude tablenames from deletion that matched the MSys pattern for the first 4 characters of the name.

Code:
dim db 
dim tb 

set db = CurrentDb 

for each tb in db.TableDefs
  If tb.Name <> "indexes" then
    If Left(tb.Name,4) <> "MSys" Then
      db.TableDefs.delete tb.name
    End If
  End If 
next

Mike
 
Upvote 0
Thanks alot, you're right, i was checking for table names and i found those...you're totaly correct...

Tx for both and good luck
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,327
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top