Pulling Formulas from Excel to MS Word

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.

Code
Sub 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
.


 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Can't you just use the Address property of the cell?
Code:
CellAddr = Cells(SRow, SCol).Address(0,0)
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top