VBA in Excel prints numbers and charts in Excel into Word

Source: Internet
Author: User

Reference: https://wenku.baidu.com/view/6c60420ecc175527072208af.html

For example, to save a selection to a picture on the desktop:

1 Subsave a selection to a picture to the desktop ()2   DimAns as BytePic as String, Paths as String3    on Error Resume Next4Paths =CreateObject("Wscript.Shell"). Specialfolders ("Desktop") &"\" 'record the path to the Desktop folder5 Star:6   'Choose the format of the exported picture7Ans = application.inputbox ("input 1: Save as BMP picture;"+Chr(Ten) +"Input 2: Save as PNG image;"+Chr(Ten) +"Input 3: Save as JPG picture. ","Picture Format",1, , , , ,1)8   IfErr <>0  Then MsgBox "only 1 to 3 can be entered", -,"Tips": Err. Clear:GoToStar'If it is wrong (the value entered is outside 0-255) returns the re-entry9   IfAns <1 OrAns >3  Then MsgBox "Input Error":GoToStar're-enter if not equal to 1, 2, 3TenPic =Choose(ANS,". BMP",". PNG",". JPG")'Choose between three formats One   If TypeName(Selection) ="Range"  Then 'If the selected object is a cell A     DimRng asRange -     SetRNG = Selection'assign a selection to a variable rng -Rng. CopyPicture Appearance:=xlscreen,Format: =xlpicture'Copy the rng area as a picture theActiveSheet.UsedRange.Rows (ActiveSheet.UsedRange.Rows.Count +1). Cells (1). Select'Select an empty cell -      withACTIVESHEET.CHARTOBJECTS.ADD (0,0, rng. Width, rng. Height). Chart'Generate chart -. Paste'paste a picture into a chart -. Export Paths &Replace(RNG. Address (0,0),":","-") & Pic'export a chart as a picture file +. Parent.delete'Delete a Chart object -     End  with +Rng. Select'Select Rng Object A   End If at   Shell "EXPLORER. EXE"& Left(Paths,Len(Paths)-1), vbMaximizedFocus'Open Desktop - End Sub
View Code

VBA in Excel prints numbers and charts in Excel into Word

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.