VBA For Screenshot...With A Twist

VinceF

Board Regular
Joined
Sep 22, 2007
Messages
199
Office Version
  1. 2016
Platform
  1. Windows
Hello Experts,
Is it possible to have a command button that when selected would open 2 tabs/pages (1 at a time I'm sure), take a screen shot and then save it to a folder?
It would open up the "MAIN" page take a screen shot and save it as the file name (Indianwood Quota.xlsm) in a .jpeg format to C:Indianwood Quota\Screenshots and then open up the 2nd tab/page called "VinE Cup" and do the same thing...screenshot/file save?

Ideally if I could put it inside of this existing VBA that I use to save the file after each round.

Sub SaveWithTodaysDate()
ActiveWorkbook.SaveAs ("C:\Golf\Indianwood Quota\Results\" & ThisWorkbook.Sheets("Main").Range("AK2").Value & ThisWorkbook.Sheets("Main").Range("AH3").Value & ThisWorkbook.Sheets("Main").Range("AJ3").Value & ".xlsm")
Range("AA3") = Range("AA3") + 1

End Sub


Thank You
VinceF
Office 2016
 
Don't quote whole posts. You're creating extra junk. Refer to a post number if needed.
Notice that you spelled the word main (Sheet Name) 3 different ways. ("MAIN", "Main", "main")
Re: "The screen shot would be of the whole sheet or screen"
What is it?
For Screen Shot, see suggestion by Skyybotat Post #10.
This code does the visible part of the sheet. No Ribbon, Formula Bar etc.
Code:
Sub Save_Visible_Part_Of_Sheet()
Dim sPath As String
Dim rRng As Object, sht As Object
Dim i As Long
Dim shArr
shArr = Array("MAIN", "VinE Cup") '    <----- Ensure spelling is same as Sheet names. Expand if needed
For i = LBound(shArr) To UBound(shArr)
Set sht = ThisWorkbook.Worksheets(shArr(i))
sPath = ThisWorkbook.Path & "\" & shArr(i) & ".jpg"
Set rRng = sht.Range(Application.ActiveWindow.VisibleRange.Address)
rRng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
With rRng.Parent.ChartObjects.Add(10, 10, 100, 100)
    .ShapeRange.Line.Visible = msoFalse
    .Height = rRng.Height
    .Width = rRng.Width
    .Chart.Paste
    .Chart.Export Filename:=sPath, Filtername:="JPG"
    .Delete
End With
Next i
End Sub
If you want it to be run when you run the macro from Post #1, you can combine both macros or go the easy way and put the macro name in the macro from Post #1
Like so:
Code:
Sub SaveWithTodaysDate()
ActiveWorkbook.SaveAs ("C:\Golf\Indianwood Quota\Results\" & ThisWorkbook.Sheets("Main").Range("AK2").Value & ThisWorkbook.Sheets("Main").Range("AH3").Value & ThisWorkbook.Sheets("Main").Range("AJ3").Value & ".xlsm")
Range("AA3") = Range("AA3") + 1
Sub Save_Visible_Part_Of_Sheet
End Sub
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Thank you all for your input...neither are working.

HighAndWilder
I get an error message saying...Ambiguous Name SubSaveRangeImageAsJPEGFile

Jolivanes
I get and error message saying... Expected End Sub with the top line of the code highlighted.

Skybot...Yes.

vinceF
 
Upvote 0
Thank you all for your input...neither are working.

HighAndWilder
I get an error message saying...Ambiguous Name SubSaveRangeImageAsJPEGFile

Jolivanes
I get and error message saying... Expected End Sub with the top line of the code highlighted.

Skybot...Yes.

vinceF
Does a procedure with the name of SubSaveRangeImageAsJPEGFile exist more than once in your project?
 
Upvote 0
Re: "I get and error message saying... Expected End Sub with the top line of the code highlighted."
You missed the "End Sub" when you copied/pasted the code.
 
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,758
Members
452,996
Latest member
nelsonsix66

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