HI ,
can any expert help on below vba. i alway got the runtime error '1004'but sometime it is running fine. just wondering if my data link is on network drive , is it due to the long time to access the network data causing the vbba not working?
Private Sub CommandButton1_Click()
Sheets("Summary").Select
Sheets("Summary").Range("C1:S9287").Select
Selection.ClearComments
Sheets("EC").Select
Range("B2:AF9287").Select
Selection.ClearContents
Range("A1").Select
For colNum = 2 To (2 + Cells(18, 1)) '23
'MsgBox (colNum)
If ((IsEmpty(Cells(1, colNum)) = False) And (IsEmpty(Cells(2, 1)) = False)) Then
fileDest = "TEXT;\\Fslfabtools\" & Cells(1, colNum) & "-FC3000\main\bin_debug\data\" & Cells(2, 1)
'MsgBox (fileDest)
With ActiveSheet.QueryTables.Add(Connection:= _
fileDest, Destination:=Cells(2, colNum))
.Name = "System_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
'insert comments
If Sheets("Summary").Cells(4, colNum) = True Then
For curRow = 2 To 9287
If Sheets("Summary").Cells(curRow, colNum) = False Then
If (IsEmpty(Sheets("EC").Cells(curRow, colNum)) = False) Then
texts = Sheets("EC").Cells(curRow, colNum)
'Sheets("Summary").Cells(curRow, colNum).ClearComments
Sheets("Summary").Cells(curRow, colNum).AddComment (texts)
Sheets("Summary").Cells(curRow, colNum).Comment.Shape.TextFrame.AutoSize = True
End If
End If
Next curRow
Else
'Sheets("Summary").Cells(1, colNum).AddComment ("Different Software Version")
'Sheets("Summary").Cells(1, colNum).Comment.Shape.TextFrame.AutoSize = True
End If
End If
Next colNum
Sheets("Summary").Select
Sheets("Summary").Range("A1").Select
MsgBox ("Complete!")
End Sub
Bookmarks