Refresh A Query

  • Thread starter Thread starter David M
  • Start date Start date
D

David M

Hello All,

I have a Macro attached to a button called "Refresh and
Format" the will refresh a query and reformat the
worksheet...I would like to be able to do this without
going to the sheet, selecting the data and then running
the macro.

Can you help me modify this code so I can just do a
refresh from where ever I am in the workbook?

Thanx

Sub Refresh_Format()
'
' Refresh_Format Macro
' Macro recorded 4/30/2004 by David Morrison
'

'
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.RowHeight = 11.25
Selection.ColumnWidth = 13.86
End Sub
 
You didn't say what you selection is but try

Sub Refresh_Format()
with sheets("yoursheetnamehere")
.QueryTables(1).Refresh BackgroundQuery:=False
.range("yourrange").RowHeight = 11.25
.range("yourrange").ColumnWidth = 13.86
end with
End Sub
 
Hi Don,

the ranges are not named...just the sheet itself and I can
use the same macro to refresh any query...I just have to
go to the query sheet and do it from there...can I use
tghe code you suggested to do this without specifying a
range?
 
try it like this to do all rows and columns in the used range.
Sub Refresh_Format()
With Sheets("sheet9")
.QueryTables(1).Refresh BackgroundQuery:=False
.UsedRange.RowHeight = 11.25
.UsedRange.ColumnWidth = 13.86
End With
End Sub
 
Okay just so I am clear....I will insert this as a new
module, attach it to a new button, go to some other
worksheet and run it from there.....the goal being to be
able to update a query, any query from anywhere is the
workbook...correct??

Thanx for the help Don..

David
 
It did work on the sheet...now what if I had several
queries...hohw can I use the same code to update all of
them with at the same time from anywhere in the
workbook...I have at least three others..

David
 
If it's all of them
for each ws in worksheets
code
'if you only want a couple
'if ws.name ="sheet1" or ws.name="sheet2" then
'code
'end if
next ws
 
Back
Top