I am looking for assistance in using variables provided by a text file with the objWS.Range(start, end).BorderAround function. My issue is that I receive a "Type Mismatch" error with the current method I use. I am using VB 6 Enterprise edition and MS Excel 2000.
The purpose of my program is to create templates in a text file that VB will call to create a spreadsheet. This allows me to create new templates (text files) without hard coding them into my VB application.
The text file contains many lines but the one I am concerned with is:
ran,border,A4,G4,xlContinuous,xlThick,xlColorIndexAutomatic
The actual command that works if hard coded in VB is:
vbcode Code:
objWS.Range("A4", "G4").BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
The code I am using that does NOT work is:
vbcode Code:
Public Function xlFeed(strInputFile As String, strOutputFile As String) Dim i As Integer Dim sngTemp As Single Dim strLine As String Dim strWord() As String Dim objXL As Object Dim objWB As Excel.Workbook Dim objWS As Excel.Worksheet Dim objRange As Excel.Range Set objXL = CreateObject("Excel.Application") objXL.Visible = True Set objWB = objXL.Workbooks.Add() Set objWS = objWB.Worksheets(1) Open strInputFile For Input As #71 Do Until EOF(71) Line Input #71, strLine strLine = Pack(strLine) strLine = Trim(strLine) strWord = Split(strLine, ",") If UBound(strWord) >= 6 Then If LCase(strWord(0)) = "ran" Then If LCase(strWord(1)) = "border" Then objWS.Range(strWord(2), strWord(3)).BorderAround strWord(4), strWord(5), strWord(6) End If End If End If Loop objWB.ActiveSheet.SaveAs (strOutputFile) objWB.Close objXL.Quit Set objRange = Nothing Set objWS = Nothing Set objWB = Nothing End Function
strInputFile is the text file; strOutputFile is a new Excel spreadsheet. When I comment out the tail of the command in question the error disappears but I do not get the border I want:
vbcode Code:
objWS.Range(strWord(2), strWord(3)).BorderAround 'strWord(4), strWord(5), strWord(6)
Any help would be greatly appreciated. Thank You,




Reply With Quote