-
Notifications
You must be signed in to change notification settings - Fork 0
/
Excel VBA - HOW to get cell formula.txt
71 lines (37 loc) · 1.3 KB
/
Excel VBA - HOW to get cell formula.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Option Explicit
Public Function seekFormula(rowIDX As Integer, colIDX As Integer) As String
Dim txtstr As String
Dim colnum As String
Dim colTxt As String
Dim isFOR As Boolean
Cells(rowIDX, colIDX).Select
txtstr = ActiveCell.FormulaR1C1
txtstr = ActiveCell.Formula
isFOR = (Left(Trim(txtstr), 1) = "=")
' Debug.Print "first letter = >>>" + Left(Trim(txtstr), 1) + "<<<"
colnum = Asc("A") + colIDX - 1
colTxt = Chr(colnum)
txtstr = colTxt + Str(rowIDX) + " === " + txtstr
If Not isFOR Then txtstr = ""
seekFormula = txtstr
End Function
Public Sub showFOR()
Dim idxR As Integer
Dim idxC As Integer
Dim linstr As String
Dim allstr As String
allstr = "" + Chr(13) + Chr(10)
For idxR = 1 To 100
For idxC = 1 To 20
linstr = seekFormula(idxR, idxC)
If Len(linstr) > 0 Then
allstr = allstr + linstr + Chr(13) + Chr(10)
End If
Next idxC
allstr = allstr + Chr(13) + Chr(10)
Next idxR
Open "d:\\xls-formula.txt" For Output As #1
Write #1, allstr
Close #1
MsgBox "Alles in Ordnung!!!"
End Sub