Okay - Hang in there with me while I try to explain...
What I have so far:
When I Create a New Document via Commandbutton1 the ActiveDocument.Name is the string value on the .txt file + 1. (I'm generating design numbers that count up). Basically for every new document via the macro is a new design number naming that document.
When I Save Document (commandbutton2) - The New Document.Name should replace the string in the txt file with 1001. But this part isnt working.
And it should keep going up from there every time i create a new document and save it.
Private Sub commandButton1_Click()
Dim TextFile As IntegerDim FilePath As StringDim FileContent As String
On Error Resume Next FilePath = "C:\Users\chier\Desktop\Design Number" & ".txt"
TextFile = FreeFile
Open FilePath For Input As TextFile
FileContent = Input(LOF(TextFile), TextFile)
ActiveDocument.Name = FileContent
Close TextFile
Dim doc1 As DocumentSet doc1 = CreateDocument() doc1.Name = FileContent + 1 End Sub
Private Sub commandButton2_Click()
'(This is where stuff starts action crazy i think). IT doesnt save properly i think.
Dim TextFile As IntegerDim FilePath As String
FilePath = "C:\Users\chier\Desktop\New Text Document" & ".txt"
Open FilePath For Output As TextFile ' Replaces Each Line in File'Open FilePath For Append As TextFile ' Adds additional Lines
On Error Resume NextPrint #TextFile, ActiveDocument.Name
ActiveDocument.SaveAs "C:\Users\chier\Desktop\" & ActiveDocument.Name & ".cdr"End Sub
Any adjustments will be helpful :)
I may not correctly understand exactly what you want to do.
Are you storing only one number? And then increasing that stored number by 1 every time a new document is created using this macro? Not saving a list of numbers in the file?
If it's just one number, then instead of storing it in a text file, have you considered having the macro store it in the Registry?
Right. I'm Only storing one number. That one number gets replaced every time the document is saved.
My goal is to auto generate a "design number" that customers reference. Trying to make it easy to track designs. I can just create a new document with the number i left off at.
I've stored a starting number on my text file. 1000.
Commandbutton1 creates a new doc and names my new doc. 1000 from my text file and adds 1 to it. Making my document name 1001.
Commandbutton2 is to save my design document in a folder and also replace 1000 with 1001 on my text file.
Then if I create a new document again via commandbutton1; it should name my new document 1002. If I save my document via the macro 1002 should replace 1001 on my text file. So on and so forth.
I dont now how to utilize the registry to do this.