Results 1 to 6 of 6
  1. #1
    Martin Vanquish is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    3

    Use vba code to add code to a word doc to prevent user from using SaveAs in Word doc

    Hi,



    I have an Access 2010 db which allows the user to browse and select an existing Word document created elsewhere. The form then copies the file to a location not known to the user and adds the new path and filename to a text field within current record.

    I would like to embed vb code to the Word doc so that it prevents the user from accessing Word's SaveAs option so that the user cannot save the file to a different location or change the filename.

    The application allows the user to open the doc from the new (unknown) location and "Save" any changes back to this location. I just want to prevent the user from saving any changes (disable SaveAs) to a location which is different to the full path/filename of that of the text field for the current record, when the file was originally attached.

    Is this feasible?

    Hope the above makes sense!

    Many thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    That's a tall order. The code wont work unless it's in every document (template).
    Even if you prevent the Save As, what about copy text from the doc then pasting into another editor?

    There may be a better expert out there that can answer this, but I dont see how.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I have never tried it for Word, but perhaps you can create a Custom Ribbon. I am not sure if a Custom Ribbon for Word is an add-in at the application level or the document level.

  4. #4
    Martin Vanquish is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    3
    any thanks for your reply.

    Re "what about copy text from the doc then pasting into another editor" - They'd soon realise that re-opening the file from the app would still open the original file.

    Is it possible to insert vba code from within MS Access into an existing Word doc?

    Many Thanks.

  5. #5
    Martin Vanquish is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    3

    Cool Solved

    I created a plain text file DisableWord_SaveAs.bas containing the following text:

    Code:
    Sub FileSaveAs()
    End Sub
    Then ran the following code:-
    Code:
    Sub temp()
      Dim wordApp As Object
      Dim wordDoc As Object
      Dim vbProj As VBProject
      Dim vbComp As VBComponent
      Dim vbMod As CodeModule
      
      Set wordApp = CreateObject("Word.Application")
    
      If wordApp Is Nothing Then
         MsgBox "Could not start Microsioft Word.", vbCritical, "Error..."
      End If
    
      Set wordDoc = wordApp.Documents.Open("<Full Path To File>)
      For Each vbProj In wordApp.Application.VBE.VBProjects
         For Each vbComp In vbProj.VBComponents
            If vbProj.Name = "Project" And vbComp.Name = "ThisDocument" Then
               vbComp.CodeModule.AddFromFile ("DisableWord_SaveAs.bas")
               Exit For
            End If
         Next vbComp
      Next vbProj
      wordDoc.Save
      wordDoc.close
      wordApp.Quit
       
      Set wordDoc = Nothing
      Set vbMod = Nothing
      Set vbProj = Nothing
      Set wordApp = Nothing
    End Sub
    The code above adds the text contained in the DisableWord_SaveAs.bas text file, to the "ThisDocument" code module under the "Project" node in the VBE - thus disabling the FileSaveAs command.

    **** Note: For the above to work, the user must have granted access to the VBA Object under:
    File | Options | Trust Centre | Trust Centre Settings... (button) | Macro Settings and tick "Trust access to the VBA object model".

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    That's pretty slick.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code to print 'section' of a word document.
    By TurnipGrnPeace in forum Access
    Replies: 6
    Last Post: 06-25-2013, 07:17 PM
  2. Replies: 3
    Last Post: 02-22-2013, 06:41 AM
  3. vba code to populat word template in Access 2010
    By graffjohn in forum Programming
    Replies: 2
    Last Post: 06-11-2011, 09:36 PM
  4. Replies: 1
    Last Post: 03-18-2011, 03:22 PM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums