|
-
Jun 16th, 2010, 03:04 PM
#1
Thread Starter
New Member
overflow error
I have an excel spreadsheet and in one column, every row contains html code. I'm trying to export the cell value that contains the code into a html file. When I run the macro created, it gives me a overflow error. Please help resolve the issue. The code is as follow:
Function SaveTextFile(strFile As String, strData As String, Optional bOverWrite As Boolean = False) As Boolean
Dim iHandle As Integer, l As Long
If Not bOverWrite Then
If Len(Dir(strFile)) > 0 Then
SaveTextFile = False
Exit Function
End If
End If
iHandle = FreeFile
l = Len(strData)
Open strFile For Binary Access Write As #iHandle Len = l
Put #iHandle, , strData
Close #iHandle
SaveTextFile = True
End Function
Function MakeString(r As Range, Optional strDelimiter As String = vbNullString) As String
Dim vArray As Variant, i As Long, j As Long, strTemp As String
If r.Count = 1 Then MakeString = r.Value: Exit Function
vArray = r.Value
For i = 1 To UBound(vArray, 1)
For j = 1 To UBound(vArray, 2)
strTemp = strTemp & vArray(i, j) & strDelimiter
Next j
strTemp = strTemp & vbCrLf
Next i
strTemp = Left(strTemp, Len(strTemp) - 2)
MakeString = strTemp
End Function
Sub Button1_Click()
Dim nrow As Long
Dim ncol As Long
Dim cellrow As Long
Dim cellcol As Long
Dim namerow As Long
Dim namecol As Long
Dim cells(cellrow, cellcol) As Long
Dim name As String
nrow = 4
ncol = 1
cellrow = 4
cellcol = 2
namerow = 2
namecol = 2
name = 1
While Not IsEmpty(Worksheets(1).cells(nrow, ncol))
Dim strMyString As String, strMyFile As String, bResult As Boolean
strMyString = "<html>" & "<body>" & cells(cellrow, cellcol) & "</body>" & "</html>"
strMyFile = "H:\desktop\" & name & ".html"
bResult = SaveTextFile(strMyFile, strMyString, True)
nrow = nrow + 1
cellrow = cellrow + 1
name = name + 1
Wend
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|