Selection.QueryTable.Refresh BackgroundQuery:=False error

Rhadida

Board Regular
Joined
Nov 26, 2003
Messages
159
Why oh why won't this work?????

Code:
Sheets("DATA1").Select
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
I use this all the time, so what can cause the problem here. BTW I get the Application-Defined or Object-Defined Error (1004).

Could it be that the Refrsh isn't finished when exceuting an other macro??? I use the DoEvents commandline after I exceute the refresh-macro. Shouldn't this force the macro to finish before it continues???
 
I had the same problem with;

Selection.QueryTable.Refresh BackgroundQuery:=False

it would work/not and then stop working after assigning it to a button it would fail and get runtime error 1004 again. It took me a while to figure out the problem. If you want to refresh the web content in sheet 1 you cannot be in sheet 2. The same applies for the macro button. The macro button you create has to be in the same sheet as the background query.

I'm a newby to VBA and Macro's it's very simple but it worked for me
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I am working with Excel 2007 and writing a macro that needs to read some text files into excel and work on them. When I used an iterative process to input text files, my macro crashed and the error is at this line

" .Refresh BackgroundQuery:=False"

If I comment out "Do Until" loop I can intake them one by one and there is no problem.

I am wondering if any one could possible guide me through this;

Kind Regards

-------------------------------------------------------------------------
Sub Prt()

Dim Bookmark1 As String
Dim Bookmark2 As String
Dim Bookmark3 As String

K = 3
Do Until Sheets("Contents").Cells(K, 2) = "END"

Bookmark1 = Sheets("Contents").Cells(3, 3)
Bookmark2 = Sheets("Contents").Cells(3, 4)
Bookmark3 = Sheets("Contents").Cells(3, 5)


'To Open External Text File and Store it in a New worksheet

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Row" & Bookmark1
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\mehdi\Desktop\My excel Education\Document1.txt", Destination:= _
Range("$A$1"))
.Name = Document1
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,038
Members
449,205
Latest member
Eggy66

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