faizan haq
New Member
- Joined
- Jan 14, 2020
- Messages
- 12
- Office Version
- 2010
- 2007
- Platform
- Windows
- 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.
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
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 Number | SO # | Order RCV Date | Customer_PO_Number | Order Quantity | Retailer_Desc | Customer Name | Stock_Type | exl File name | Jpg file name |
75 | 1 | 49022036 | 7-Dec-20 | 1265898626J0100 | 671 | Adidas | Style Textile (PVT) Ltd | 4-215871 | for print out.xlsx | 1.jpg |
5 | 2 | 49022026 | 7-Dec-20 | 126911114ID0100 | 810 | Adidas | Interloop Limited | AD-HTB | for print out.xlsx | 2.jpg |
9 | 3 | 49022054 | 7-Dec-20 | 127092593GY0100 | 667 | Adidas | Style Textile (PVT) Ltd | AD-AUSHT | for print out.xlsx | 3.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