I've many a time researched problems on Stack Overflow and found solutions. This is the first time I'm posting a problem, since I'm really stuck. I've recently worked through Siddharth Rout Tutorial on VB.Net and excel Automation. A very good turotial that has helped me a lot and I can recommend. In my program so far, I'm writing a lot of information directly to a worksheet3 worksheet, but this is taking too long (test data is 1517 lines from blocks A to Ay and AA to AY, can also be blocks BA1 to BY1 and CA1 to to CY1 and double the amount of lines, depending on the configuration of the data). I'm not sure if it's taking long because I'm referencing a number of arrays for the purpose of combining column lables and row numbers for the strings of the ranges and then a 4 dimensional array that contains the values to be written. It must be the writing to the excel app itself. It's not that the number crunching methods can be the cause either, I use much more complicated number crunching methods in other parts of the program that output to text files like lightning.
So now I'm investigating rather importing all this data from a csv file that I have create into worksheet3, but I'm getting stuck with errors from the compiler at run time. The code I've researhced and tweaked advised a queary table, and I don't know if I'm barking up the wrong alley using a query table(if anyone can advise a better method to import the data into a specific worksheet, I'll gladly try it out, after importing, i'm just gonna apply some formatting of the cells and add some excel calcualtions in cells that have been left empty for this purpose)
The error i'm getting at runtime on the xlworkSheet3.QueryTables.Add line states:
_Default = In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
evaluating the error further provides the following: _Default = Argument not specified for parameter 'Index' of 'Public ReadOnly Default Property _Default(Index As Object) As Microsoft.Office.Interop.Excel.QueryTable'.
And I have no idea what it's referring to. Below is my code, I'm coding VB in VS Express 2013 For Desktop. I'm not a profesional programmer, but find it usefull in my trade. Hope someone can help.
Dim strName As String = Mid(strFileName, 1, (strFileName.Length() - 4))
Dim strRangeStart As String = "A1"
Dim strRangeEnd As String = "AY1517"
''Reason I'm using strRangeStart and strRangeEnd: at Runtime the error
''came up to use objects in the Range field
''Reason I'm using a Begin and End range: at runtime error came up to
''use a specific range, not just "A1" or "$A$1" as in researched example
''codes.
With xlworkSheet3.QueryTables.Add(Connection:=strCSVOutputPath,
Destination:=xlworkSheet3.Range(strRangeStart, strRangeEnd))
.Name = strName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = Excel.XlCellInsertionMode.xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = Excel.XlTextParsingType.xlDelimited
.TextFileTextQualifier = Excel.XlTextQualifier.xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
''.TextFileColumnDataTypes =
''my compiler does not like the = Array(1,1,1,1,1) statements,
''so I'm leaving this out hoping General will apply
.TextFileTrailingMinusNumbers = True
.Refresh(BackgroundQuery:=False)
End With
Aucun commentaire:
Enregistrer un commentaire