Trouble with VBA driven screenshot

leurp

New Member
Joined
Jun 11, 2018
Messages
5
Good morning (in W. Europe ;))
I’m working with a scripting dictionary composed with instances of a custom class of mine and of course it can’t be registered. My solution in order to keep the relative data is to write my instances’ information into an userform, make a screen capture of the usf and paste it into a dedicated workbook. I have in a standard module the code opening my userform (fiche_ind, sorry, names are in French) and in the usf module the code for the screen capture (please see below): The problem ist that after the instruction opening the userform nothing else occurs: the evenemential sub doesn’t start. I tried to have the whole code in the standard module but then the prtscr captured the code page !
Code:
 'ouvre le classeur d'images =opens the img workbook
        Workbooks("images_compos.xlsx").Activate
        ActiveWorkbook.ActiveSheet.Name = NomComplet
        fiche_ind.Show   ' a userform
The userform code
Code:
Private Sub fiche_ind_Initialize()
Dim Ws As Worksheet
Dim legende As String
Dim photo As Object
SendKeys (PRTSC)
        Workbooks("images_compos.xlsx").Activate
        ActiveWorkbook.ActiveSheet.Name = NomComplet
            With ActiveSheet.PageSetup
                '...
            End With
            With ActiveSheet
                With New DataObject
                .GetFromClipboard
                End With
            .Cells(1, 1).value = legende
            .Range(Cells(2, 1), Cells(25, 11)).Select
            End With
        ActiveSheet.Paste
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub
Thank you for any help or explanation.
Regards
Pierre
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the forum.

It’s always Userform_Initialize no matter what the name of the form is.
 
Upvote 0
Good morning Rory,
Welcome to the forum.

It’s always Userform_Initialize no matter what the name of the form is.
It works fine, thank you, but there's another issue. Apparently the Sendkeys (PRTSC) instruction doesn't trigger anything because at the end my "PrintOut" instruction prints the last "copy-paste" I've made before working with Excel instead of a picture of my userform or anything else in Excel.
What's wrong in my code ?
Thank you for any help.
Regards
Leurp
 
Upvote 0
Thanks Rory,
I'll be happy to folllow the example of "serious developers" although I'm just an amateur.
have a fine day
P.
 
Upvote 0
Good afternoon,
Sorry but I'm still stuck with my automated screen capture. I went there: https://www.mrexcel.com/forum/redirect-to/?redirect=https://wordmvp.com/FAQs/MacrosVBA/PrtSc.htm and tried first the version "to capture the active window" and it worked apparently well but each time I got a print out of my code page ! I tried then with "to capture the screen" and it didn't work at all. After the lines
Code:
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
  bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long
I get the msg (I translate approximately)
only comments can appear after End Sub, End Functin or End Property
but I can't see any "End" anything causing the error.
Can anybody explain ?
Many thanks in advance.
Best regards
Pierre alias leurp
 
Upvote 0
The declaration has to be at the top of the code module, before any procedures.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top