Here is the small script I wrote:
Option Explicit
Dim strFileFullName As String
Sub saveToText()
Open "PATH\File.txt" For Append As #1
Print #1, strFileFullName = ActiveWorkbook.FullName
Print #1, Sheets("Overview").Range("D14").Text
Close #1
End Sub
Also I would like to add some extra text to the .txt file that is not in the excel workbook. How would I go about doing that? Thanks!
VB does not have a distinction between the comparison operator and the assignment operator. That is, they are both
=. In this case, it is being interpreted as the comparison operator, which is returning false. (Compare this to C, where the comparison operator is==and the assignment operator is=; what you are trying to do here would work in C as an inline assign)It doesn’t look like you need the extra variable there, so you should be able to just do:
Or, use two statements (VB will understand this as an assignment, not a comparison):
Adding text is as simple as adding another print statement: