Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I love this site! It's so nice to know that there are so many people out there who are willing to share their knowledge..."

Geography

Where in the world do Tek-Tips members come from?

Excel 2010 gets error message on recorded macro

MarshaP (Programmer)
8 Aug 12 15:43
I recorded a macro in Excel 2010 to run a saved query and return the data. When I run the macro, I get a run-time error 5, invalid procedure call or argument. This is the code generated by the macro recorder:

Sub Macro5()
'
' Macro5 Macro
'
'
Workbooks.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Destination:=Range("$A$1")) _
.QueryTable
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_GL_Query_002"
.Refresh BackgroundQuery:=False
End With
End Sub


It ran OK when I was recording the macro, and runs OK if I run the query within Excel.

Thanks for any help.
SkipVought (Programmer)
8 Aug 12 15:54
hi,

Your macro ADDs a NEW querytable EVERY SINGLE TIME.

This clutters your sheet with unnecessary objects and it totally unnecessary.

All you need do, once a QT is added, is to REFRESH the QT. If you want to do this via code...

CODE

activesheet.listobjects(1).querytable.refresh false 

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close