Consulting

Results 1 to 5 of 5

Thread: Word commandbutton does not do what I want.

  1. #1
    VBAX Newbie
    Joined
    Oct 2020
    Posts
    3
    Location

    Question Word commandbutton does not do what I want.

    Hello,

    In Word 2019 I have made a template with inputfields for my colleagues. At the bottum is a commandbutton.
    When finishing the inputfields, they have to push the button.

    - Is scrolls up the page (nessesary for the filename)
    - it shows a messagebox (for the filename)
    - it will save the file as PDF

    The code is:

    Private Sub CommandButton1_Click()
    Dim Map As String
    Dim Bestandsnaam As String
    ActiveWindow.SmallScroll Down:=-35
    
    With ActiveDocument
        
        .Shapes(1).Visible = msoFalse       'To hide the button for making a pdf
        Map = "C:\RvB\"                    
        Bestandsnaam = InputBox("Idem als de mail, bijvoorbeeld:  W-postcode+nr-plaats-naam", "Bestandnaam invullen") & ".pdf"
        ActiveDocument.ExportAsFixedFormat OutputFileName:=Map & Bestandsnaam, ExportFormat:=wdExportFormatPDF, _
            OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, UseISO19005_1:=False
        .Shapes(1).Visible = msoTrue
        
    End With
    End Sub
    Knipsel.JPG

    The problem is:

    When word is in editing limited (Sorry, I have a Dutch version of Word) and its protect with '2. fill in forms' (So the users can only tab to the inputfields), this code doesn't work. When the protection 'fill in forms' is not checked en I secure it, then it works. But that's not what I want.

    Is is possible to get this code working?
    There is no password required.

    RvB_20201020_TEST.zip
    Grz Robert, Netherlands

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,218
    Location
    Why don't you just move you code to a button on the Quick Access Toolbar. ActiveX controls (command buttons) in documents are after all a bit dated.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Oct 2020
    Posts
    3
    Location
    And that will work. Somethimes if you know, it's that simple...

    But there is still a problem with the popup.
    When the popup appears and I will choose CANCEL or X, I get an error (dubugging: yellow: ActiveDocument.ExportAsFixedFormat OutputFileName.. etc..)

    Is there a solution for that?

    Greetz Robert

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,218
    Location
    Dim Map As String
    Dim Bestandsnaam As String
    ActiveWindow.SmallScroll Down:=-35
    
    With ActiveDocument
        
        '.Shapes(1).Visible = msoFalse       'To hide the button for making a pdf
        Map = "C:\RvB\"
        Bestandsnaam = InputBox("Idem als de mail, bijvoorbeeld:  W-postcode+nr-plaats-naam", "Bestandnaam invullen") & ".pdf"
        If Len(Bestandsnaam) > 4 Then
          ActiveDocument.ExportAsFixedFormat OutputFileName:=Map & Bestandsnaam, ExportFormat:=wdExportFormatPDF, _
            OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, UseISO19005_1:=False
        '.Shapes(1).Visible = msoTrue
        End If
    End With
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Newbie
    Joined
    Oct 2020
    Posts
    3
    Location
    Tnx Greg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •