From: johnnykunst on 21 May 2010 06:06 Thanks for your help- the problem seems to have been caused by having an identical document on the desktop- now I've deleted it the original runs fine. --- frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general/Code-only-works-fully-when-run-from-VBA-editor
From: johnnykunst on 1 Jun 2010 07:57 Turned out to be because I had set the module name the same as the macro it contained. I then had the problem of the document saving as un recognised format in some instances, but I worked out this was because of illegal characters such as \/|.:?" being entered into the text form field and ending up in the filename, so I inserted an on-exit macro from the fileds to remove the illegal characters. Now works perfectly, macro is: Sub KeywordsCleanUp() Dim s As String s = ActiveDocument.FormFields("Keywords").Result ActiveDocument.FormFields("Keywords").Result = RemoveIllegalCharacters(s) End Sub Which uses the following function: Function RemoveIllegalCharacters(s As String) As String Dim e As Variant e = Array("\", "/", ":", "*", "?", """", "<", ">", ".", "|", "[]", Chr$(13)) Dim temp As String temp = s Dim c As Variant For Each c In e temp = Replace(temp, c, "") Next RemoveIllegalCharacters = temp End Function --- frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general/Code-only-works-fully-when-run-from-VBA-editor
First
|
Prev
|
Pages: 1 2 Prev: Insert Landscape within Portrait Next: Using Excel Functions in VBA Word |