Paste value & insert image & take print by VBA

faizan haq

New Member
Joined
Jan 14, 2020
Messages
12
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
  2. MacOS
Hi,

I have done vba code regarding below that this below value past in " for print out.xlsx " an other file which is available in located folder, and i also want to insert pictures of each file after value paste and take print out and close, almost i have done vba code for below but i want to remove selection image window below red highlighted line in vba code. it should be inserted automatically by file name which is mentioned in excel file or in folder one by one.


Sno.Ticket Express NumberSO #Order RCV DateCustomer_PO_NumberOrder QuantityRetailer_DescCustomer NameStock_Typeexl File nameJpg file name
75​
1​
49022036​
7-Dec-20​
1265898626J0100
671​
AdidasStyle Textile (PVT) Ltd4-215871for print out.xlsx1.jpg
5​
2​
49022026​
7-Dec-20​
126911114ID0100
810​
AdidasInterloop LimitedAD-HTBfor print out.xlsx2.jpg
9​
3​
49022054​
7-Dec-20​
127092593GY0100
667​
AdidasStyle Textile (PVT) LtdAD-AUSHTfor print out.xlsx3.jpg

VBA code:.
Sub copy_value_in_file()
Dim m As Long, sPath As String, sFile As String, sh As Worksheet
Dim fNameAndPath As Variant
Dim img As Picture

Application.ScreenUpdating = False

Set sh = ActiveSheet
sPath = ThisWorkbook.Path & "\"
For m = 1 To 200
sFile = Range("J" & m).Value
If sFile <> "" And Dir(sPath & sFile) <> "" Then
Workbooks.Open (sPath & sFile)

Range("A6").Value = sh.Range("A" & m).Value
Range("B6").Value = sh.Range("B" & m).Value
Range("C6").Value = sh.Range("C" & m).Value
Range("D6").Value = sh.Range("D" & m).Value
Range("E6").Value = sh.Range("E" & m).Value
Range("F6").Value = sh.Range("F" & m).Value
Range("G6").Value = sh.Range("G" & m).Value
Range("H6").Value = sh.Range("H" & m).Value
Range("I6").Value = sh.Range("I" & m).Value


fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub
Set img = ActiveSheet.Pictures.Insert(fNameAndPath)

With img
'Resize Picture to fit in the range....
.Left = ActiveSheet.Range("A9").Left
.Top = ActiveSheet.Range("A9").Top
.Width = ActiveSheet.Range("A9:I9").Width
.Height = ActiveSheet.Range("A9:I78").Height
.Placement = 1
.PrintObject = True
End With

ActiveWorkbook.Close True
End If
Next
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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