PDA

View Full Version : enable macros dialog box...HIGH PRIORITY



lazyuser
02-24-2009, 01:12 PM
the requirement:

i am working with word macros. when i open a word document, i get this security warning dialog box. i click on enable macros and it goes off. i have some macros coded in this document - that adds some buttons.

one of the buttons opens word documents in a specified folder and does something on the document and saves each document with a prefix "NEW_". each document in the folder is worked on and saved - in batch mode. when all documents are done, i flash a message saying 'X number of documents have been processed.'

the issue:

i am guessing that this security warning dialog box keeps popping up for each document and i need to suppress that. is there a way to do this? if yes, how?

thankssss

lucas
02-24-2009, 01:24 PM
You don't say what version but in 2003 go to tools-macro-security

under the security level tab, select "low"

Be aware, this will allow any macro to run in any word document you open.

lazyuser
02-24-2009, 01:28 PM
You don't say what version but in 2003 go to tools-macro-security
under the security level tab, select "low"
Be aware, this will allow any macro to run in any word document you open.
office 2003 is what i am using. is there not a better way to handle this then?

i do not get this error (run time error 5479) when i run the program from within my vba code. but,when i close the code and run it from word alone, i get this.

i tried changing the security settings to low: it still does it.

lucas
02-24-2009, 01:37 PM
We would have to at least see the code and it would be nice if you could post a clean and lean example document.

lazyuser
02-24-2009, 01:52 PM
We would have to at least see the code and it would be nice if you could post a clean and lean example document. heres the code:



Private Sub cmdRunProcess_Click()

Dim objFSO As New Scripting.FileSystemObject
Dim objfolder As Folder
Dim objFile As File
Dim objNewFile As File
Dim nNumDocs As Integer
Dim objDoc As Document
Dim index As Long
Dim docCount As Integer

If txtSourceFolder = "" Then
MsgBox "Source Folder cannot be blank. Please select a " & _
"Source Folder.", vbOKOnly, appName
End
End If
If txtDestinationFolder.Text = "" Then
MsgBox "Destination Folder cannot be blank. Please select a " &_
"Destination Folder.", vbOKOnly, appName
End
End If

Dim docCount As Long

If (objFSO.FolderExists(txtSourceFolder.Text)) Then
Set objfolder = objFSO.GetFolder(txtSourceFolder.Text)
'check to see if any files exist in the folder
If objfolder.Files.Count = 0 Then
MsgBox "There are no documents to be processed " & _
"in this folder!", vbOKOnly, appName
Exit Sub
Else
' if there are no .DOC files
' may as well get out now
' so count them
For Each objFile In objfolder.Files
If Right(UCase(objFile.Name), 4) = ".DOC" Then
docCount = docCount + 1
End If
' if count = 0 then bye bye
If docCount = 0 Then
MsgBox "No Word Documents exist in selected folder.", _
vbOKOnly, appName
Exit Sub
End If
Next

' anything after means there ARE files
' and there ARE .DOC files
' but RESET docCount to collect the number
' of files actually processed
docCount = 0

For Each objFile In objfolder.Files
' check for files ending with .DOC extension
' and NOT "NEW_"
' only those files will be actioned
If Right(UCase(objFile.Name), 4) = ".DOC" And _
Left(UCase(objFile.Name), 4) <> "NEW_" Then
' file IS .doc and NOT "New_"
' so do the action
Set objDoc = Word.Documents.Open(objFile.Path)
FindCitations
With objDoc
.SaveAs (txtDestinationFolder.Text & _
"NEW_" & objFile.Name)
.Close
End With
docCount = docCount + 1
End If
Next ' to the next file
End If
Else
MsgBox "Specified folder does not exist. " & _
"Please choose a valid folder.", vbOKOnly, appName
txtDestinationFolder.SetFocus
Exit Sub
End If

MsgBox docCount & _
" Documents have been processed successfully!", _
vbOKOnly, appName


End Sub

i have a user form with two buttons and two text fields to input the source and destination folders. i provide this information, and then hit the Run Process button that triggers this code.

if any valid documents are found, "FindCitations" function is called from another module. that function works on the file and i then save it. i then pick up the next document. and then the next. and so on.

i get the error after it says it found 'X number of documents' in the folder. it just spits out the run time error 5479 dialog box and terminates my application.

fumei
02-24-2009, 02:29 PM
I am not going to answer as the code window is way too wide, and I am tired.

I tried to make your code a bit leaner in the other thread.

BTW: you may as well start declaring your numeric variables as Long, not Integer. VBA no longer does anything with integers. It automatically converts ALL Integers to Longs.

lazyuser
02-24-2009, 03:02 PM
I am not going to answer as the code window is way too wide, and I am tired.

I tried to make your code a bit leaner in the other thread.

BTW: you may as well start declaring your numeric variables as Long, not Integer. VBA no longer does anything with integers. It automatically converts ALL Integers to Longs.
i copy pasted the code you gave me in the other thread. hope that helps. i did not realize you were talking about the width of the code when you suggested using "_" .