Stealth2016
New Member
- Joined
- Oct 26, 2016
- Messages
- 34
I found the following Macro on the Internet for pulling formulas from a worksheet and putting them into a MS Word document. It works really well but doesn't recognise Column addresses after "Z". Instead of "AA, AB, AC etc it displays a, b, c etc. Is there any way of fixing this minor problem in the VBA.
CodeSub WriteFormulasToWord() Dim Wrd As New Word.Application
Dim CellTxt As String
Dim CellAddr As String
Dim SRow As Long
Dim SCol As Long
Wrd.Visible = True
Wrd.Documents.Add
Wrd.Selection.TypeText Text:="List of the Formulas of Sheet """ _
& ActiveSheet.Name & """ in Workbook """ _
& ActiveWorkbook.Name & """."
Wrd.Selection.TypeText Text:=vbCrLf & vbCrLf
'Change the following line to pick the number of columns
For SCol = 1 To 5
'Change the following line to pick the number of rows
For SRow = 1 To 10
If Cells(SRow, SCol).HasFormula Then
CellAddr = Chr(64 + SCol) & Trim(Str(SRow)) & vbTab
CellTxt = ActiveSheet.Cells(SRow, SCol).Formula
Wrd.Selection.TypeText Text:=CellAddr & CellTxt
Wrd.Selection.TypeText Text:=vbCrLf
End If
Next SRow
Wrd.Selection.TypeText Text:=vbCrLf
Next SCol
End Sub
.
CodeSub WriteFormulasToWord() Dim Wrd As New Word.Application
Dim CellTxt As String
Dim CellAddr As String
Dim SRow As Long
Dim SCol As Long
Wrd.Visible = True
Wrd.Documents.Add
Wrd.Selection.TypeText Text:="List of the Formulas of Sheet """ _
& ActiveSheet.Name & """ in Workbook """ _
& ActiveWorkbook.Name & """."
Wrd.Selection.TypeText Text:=vbCrLf & vbCrLf
'Change the following line to pick the number of columns
For SCol = 1 To 5
'Change the following line to pick the number of rows
For SRow = 1 To 10
If Cells(SRow, SCol).HasFormula Then
CellAddr = Chr(64 + SCol) & Trim(Str(SRow)) & vbTab
CellTxt = ActiveSheet.Cells(SRow, SCol).Formula
Wrd.Selection.TypeText Text:=CellAddr & CellTxt
Wrd.Selection.TypeText Text:=vbCrLf
End If
Next SRow
Wrd.Selection.TypeText Text:=vbCrLf
Next SCol
End Sub
.