Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using alternative credentials to save mailmerge instead of current domain user 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

Is it possible to tell VBA to use a different domain user account to save a document that isn't the account for the logged on current domain user.

The server guys set permissions on the server share to not allow 'delete' permissions so users couldn't move / delete folders or files, only the VBA code then couldn't create a new word document from a memory resident mail merge.

Code:
    Set WordApp = CreateObject("Word.Application")

    'Open document
    WordApp.Documents.Open sFile
    WordApp.Visible = False
    
    'issue mailmerge command
    With WordApp.ActiveDocument.MailMerge
        .MainDocumentType = wdFormLetters
        .OpenDataSource Name:=cDrive & "\AccessDataSource.xls", _
        readonly:=True, Connection:=sTable, SubType:=wdMergeSubTypeWord, _
        SQLStatement:="Select * From [" & sTable & "]"
        .Destination = wdSendToNewDocument
        .Execute
    End With

    ' Save mailmerge
    WordApp.ActiveDocument.SaveAs FileName:=sWord, FileFormat:=wdWordDocument, ReadOnlyRecommended:=True

The last line that tries to save the document fails once 'delete' permissions have been removed from the user.

How do I get round this?

Can I set the account to use when trying to save the document?

Thanks,
1DMF


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
How do I get round this?
Well, ask the server guys ...
 
I have , but so far they haven't been able to help.

In fact the fist permissions change they made stopped everyone from being able to access the drive/share altoghether.

I can get them to set up an account that has certain permissions, but need to know how programaticaly in VBA I then 'use' those credentials for saving the documents / creating folders etc.

Is this possible in VBA?


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
>In fact the fist permissions change they made stopped everyone from being able to access the drive/share altoghether

I think PHV is trying to suggest that it shouldn't be your job to work around limitations server team ..
 
I'm not trying to work around limitations. I'm trying to impose them?

I am requesting the drive is locked down so users cannot delete folders / files or move them, they are corrupting one of our shares and rag/dropping company folders all over the place, I need to stop this.

I was told by the server support guys that if they remove 'delete' permissions from domain users then this will have that affect, and in Windows Explorer it does, only for some reason now VBA can't 'SAVE' a file to that network share?

So either you are suggesting they screwed up the permissons and that is why 'SAVE' isn't working either, or the way MS saves a document performs some type of 'RENAME' which can't be done without 'DELETE' permission (as is the same case in Windows Explorer).

So if possible I want to get VBA to run with a particular user account with the right permissions when trying to save a mailmerge to this network share.

However, if PHV is suggesting not allowing 'move/delete/rename' of folders on a network share while allowing VBA to save word documents via the above code to these network shares is possible, with a simple permissions setting on the PDC, please can you provide me the setting so I can tell the server guys EXACTLY the settings I need to lock this drive down as desired.

Thanks,
1DMF.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
>the way MS saves a document

Word uses temporary files when saving a document, which then need to be deleted. If they cannot be deleted, you cannot save. Which is what you are finding.

But why not run the mailmerge to an open location, and then just copy/move it to the locked down share (since it is perfectly feasible to have a folder and its subfolders locked down against deletion and/or modification, but still allow new files and folders to be created)? No special account needed.
 
Word uses temporary files when saving a document, which then need to be deleted. If they cannot be deleted, you cannot save. Which is what you are finding.

So even though the mailmerge template is from a different network share that the user has full permissions over, and the word document is memory resident and no trace of it is on the network share that it tries to save to, it still uses a temp file to save in the target location that then can't be deleted? Dang.. bit inconvenient - lol

I guess that is an easier option, OK, I'll need to re-write the document managment code to save the file locally, then move or (copy/delete) to desired final destination, but it isn't that much code refactoring and no doubt easier than trying to mess with accounts / privileges!

Thanks for clarifying this Mike, apprecitaed.


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top