Code to import text via connections creates Add-in???

ron2k

Board Regular
Joined
Jan 28, 2008
Messages
139
Hey guys,

I have the following code which is run by a form. It imports text via connection. However, I notice that every time I run it it creates an Add-in and names it by whatever value cboRptname (a combobox field on the form) has. This creates a real nuisance as every time I open Excel (thereafter) it gives me a message that that add-in is not found:
Code:
Private Sub ImportText()
Set ws1 = Sheets(cboRptname.Value)

ws1.Activate
With ws1
    ActiveSheet.AutoFilterMode = False
    ActiveWindow.FreezePanes = False
    ws1.UsedRange.Clear
End With

With ws1.QueryTables.Add(Connection:= _
        "TEXT;\\nbsmain\Archive\sxxirpts\" & cboYear.Value & " " & cboMonth.Value & " Sxxi Reports\Main\" & cboMonth.Value & cboDay.Value & "\F99999\" & cboRptname.Value & ".999", Destination:= _
        ws1.Range("$A$1"))
        '\\nbsmain\Archive\sxxirpts\2011 03 Sxxi Reports\Main\0331\F99999\PSAV00.999
        .Name = "cboRptname.Value"
        .FieldNames = True
        .PreserveFormatting = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileOtherDelimiter = "|"
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
End With
End Sub

Is there a way I need to rewrite the above to avoid that? As well, how do I provide to give the user a message if the text file location is not found?

Thanks a ton

Ron
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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