Ik ben in word bezig om via een macro bestanden aan te maken.
De eerste versie heb ik genaakt via opnemen:
Zet ik 1234-xxxx in een variabele dan gaat het fout bij het opslagen van het bestand.
Wie heeft de oplossing voor mij? TIA
De eerste versie heb ik genaakt via opnemen:
Code:
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy \\hier lees ik de bestandsnaam in, nu 1234-xxxx
ChangeFileOpenDirectory "S:\2012\"
Documents.Open FileName:= _
"S:\2012\org.docx", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "FonsP"
.Replacement.Text = "1234-xxxx"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ChangeFileOpenDirectory "S:\2012\"
ActiveDocument.SaveAs2 FileName:= _
"S:\2012\1234-xxxx.docx" _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=14
ActiveDocument.Close
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Zet ik 1234-xxxx in een variabele dan gaat het fout bij het opslagen van het bestand.
Code:
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
bestandsnaam = Selection
ChangeFileOpenDirectory "S:\2012\"
Documents.Open FileName:= _
"S:\2012\org.docx", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "FonsP"
.Replacement.Text = bestandsnaam
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ChangeFileOpenDirectory "S:\2012\"
[COLOR="#FF0000"] ActiveDocument.SaveAs2 FileName:= _
"S:\2012\" & bestandsnaam & ".docx" _
, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=14[/COLOR]
ActiveDocument.Close
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Laatst bewerkt: