Refresh .CSV Connection - No Prompts

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Hi i'm trying to refresh a connection in a workbook using vba, (using a refresh every ten minutes will take up too much resource), i want to avoid prompts coming on screen.

So far this is what i have

it breaks at:
.Refresh BackgroundQuery:=False

And comes up with:
Run-Time error '1004':
Excel cannot find the text file to refresh this external data range.
Check to make sure the text file has not been moved or renamed, then try the refresh again

Rich (BB code):
Sub Rifresh()
pathfile = "C:\Documents and Settings\user.name\DataLog.csv"
Sheets(k + 1).Activate
Range("A1").Select
With Selection.QueryTable
    .Connection = _
    "TEXT;" & "C:\Documents and Settings\user.name\DataLog.csv"
    .TextFilePlatform = 850
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileCommaDelimiter = True
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
    .TextFileTrailingMinusNumbers = True
    .TextFilePromptOnRefresh = False
    .Refresh BackgroundQuery:=False
End With
End Sub


This is the code i worked it from if it helps

Rich (BB code):
pathfile = "C:\" & path & "\" & uest & "\" & filename(k) 
Sheets(k + 1).Activate 
Range("A1").Select 
With Selection.QueryTable 
    .Connection = _ 
    "TEXT;" & pathfile 
    .TextFilePlatform = 850 
    .TextFileStartRow = 1 
    .TextFileParseType = xlDelimited 
    .TextFileTextQualifier = xlTextQualifierDoubleQuote 
    .TextFileCommaDelimiter = True 
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1) 
    .TextFileTrailingMinusNumbers = True 
    .TextFilePromptOnRefresh = False 
    .refresh BackgroundQuery:=False 
End With

I've also tried it with the Pathfiles referencing the xls file that gets updated as i'm unsure what should be referenced.

Any help would be appreciated.

Thanks
 

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 using the display warnings option. I also think your path maybe wrong as you don't normally have a full stop

pathfile = "C:\Documents and Settings\user.name\DataLog.csv"


Sub upd()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
'Your code
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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