dj44
03-15-2016, 04:17 PM
Folks,
good day and evening to all.:)
I am trying to Insert a DocId number into a folder full of documents.
Now that I found all my good files. I need to catalogue them all. So in the future there is no chance of losing them.
What I mean by DocId - is each document will have a unique number inserted into it.
I need this DocID number to be inside the document, not as part of the file name.
I will give it a starting number eg 1200
The file name is not important - just to make sure that each file gets a sequential number inserted into it.
Example:
File1 : DocId 1201
File2 : DocId 1202
File3 : DocId 1203
My not so great version number 30+. I have been trying to write this script for the past week.
Sub InsertIDS()
'This is to insert a unique number into each document so that it can be catalogued
Dim SeqNumber, SeqStartNumber As Integer
Dim i as long
Dim file
Dim path As String
path = "C:\Users\DJ\Desktop\Files\"
SeqStartNumber = 2034
'Another loop of some kind? There is one already
file = Dir(path & "*.docx")
Do While file <> ""
Documents.Open FileName:=path & file
With ActiveDocument.Paragraphs(1).Range
.InsertBefore "DocID - " & SeqStartNumber++ ' This is wrong
file = Dir()
Loop
'Now move on to the next file and insert id
End With
End Sub
Now i have been testing all sorts for the past week and well - it turned up dud all my efforts.
Some help from the kind pros is needed.
A pro master must know how i have gone wrong, please advise.
I hope I am not running up the wrong tree here
thank you and cheers for your valuable advice:)
DJ
good day and evening to all.:)
I am trying to Insert a DocId number into a folder full of documents.
Now that I found all my good files. I need to catalogue them all. So in the future there is no chance of losing them.
What I mean by DocId - is each document will have a unique number inserted into it.
I need this DocID number to be inside the document, not as part of the file name.
I will give it a starting number eg 1200
The file name is not important - just to make sure that each file gets a sequential number inserted into it.
Example:
File1 : DocId 1201
File2 : DocId 1202
File3 : DocId 1203
My not so great version number 30+. I have been trying to write this script for the past week.
Sub InsertIDS()
'This is to insert a unique number into each document so that it can be catalogued
Dim SeqNumber, SeqStartNumber As Integer
Dim i as long
Dim file
Dim path As String
path = "C:\Users\DJ\Desktop\Files\"
SeqStartNumber = 2034
'Another loop of some kind? There is one already
file = Dir(path & "*.docx")
Do While file <> ""
Documents.Open FileName:=path & file
With ActiveDocument.Paragraphs(1).Range
.InsertBefore "DocID - " & SeqStartNumber++ ' This is wrong
file = Dir()
Loop
'Now move on to the next file and insert id
End With
End Sub
Now i have been testing all sorts for the past week and well - it turned up dud all my efforts.
Some help from the kind pros is needed.
A pro master must know how i have gone wrong, please advise.
I hope I am not running up the wrong tree here
thank you and cheers for your valuable advice:)
DJ