Choose to Insert Image as an Image or as a Comment - excel

I have code which inserts images from the given path using specific set of numbers against which I already have an image database.
Sub InsertPics()
Dim fPath As String, fName As String
Dim r As Range, rng As Range
Dim shpPic As Shape
Application.ScreenUpdating = False
fPath = "C:\Users\DELL\Documents\FY18-19\Images\"
Set rng = Range("D2:D" & Cells(Rows.Count, 4).End(xlUp).Row)
For Each r In rng
On Error GoTo errHandler
If r.Value <> "" Then
Set shpPic = ActiveSheet.Shapes.AddPicture(Filename:=fPath & r.Value & ".jpg", linktofile:=msoFalse, _
savewithdocument:=msoTrue, Left:=Cells(r.Row, 2).Left, Top:=Cells(r.Row, 2).Top, Width:=-1, Height:=-1)
With shpPic
.LockAspectRatio = msoTrue
If .Width > Columns(2).Width Then .Width = Columns(2).Width
Rows(r.Row).RowHeight = .Height
End With
End If
errHandler:
If Err.Number <> 0 Then
Debug.Print Err.Number & ", " & Err.Description & ", " & r.Value
On Error GoTo -1
End If
Next r
Application.ScreenUpdating = True
End Sub
I need to do the below as well:
ask the file path
ask whether to insert the image as image or as a comment against those set of numbers and run accordingly
If the code can be converted into a select mode run, i.e. on a set of numbers I can run the code for (instead of the entire 'D'-Column I've embedded currently).

May try this code and modify to your requirement.
Sub InsertPics()
Dim fPath As String, fName As String
Dim r As Range, rng As Range
Dim shpPic As Shape, IsCmnt As VbMsgBoxResult
'Application.ScreenUpdating = False
Set rng = ThisWorkbook.ActiveSheet.Range("D2:D" & Cells(Rows.Count, 4).End(xlUp).Row)
On Error GoTo Xexit
Set rng = Application.InputBox("Select the range to import Images", "Import Image", rng.Address, , , , , 8)
On Error GoTo 0
If rng Is Nothing Then Exit Sub
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = " Select Folder to Upload Images"
.AllowMultiSelect = False
.InitialFileName = "C:\Users\user\DeskTop\"
If .Show <> -1 Then Exit Sub
fPath = .SelectedItems(1)
End With
fPath = fPath & "\"
'Avoided further asking wheather all Images are to be uploaded as Comment
'instead used bold font of the file names to do the same
'try Next statement, if want all the images as comment
'IsCmnt = MsgBox("Is the images to be uploaded as comments", vbYesNo)
For Each r In rng
If r.Value <> "" Then
If Dir(fPath & r.Value & ".jpg") <> "" Then
'If IsCmnt = vbYes Then 'try this branch if want all the images as comment
If r.Font.Bold Then ' instead of asking multiple times
r.ClearComments
r.AddComment ""
r.Comment.Shape.Fill.UserPicture fPath & r.Value & ".jpg"
Else
Set shpPic = ActiveSheet.Shapes.AddPicture(Filename:=fPath & r.Value & ".jpg", linktofile:=msoFalse, _
savewithdocument:=msoTrue, Left:=Cells(r.Row, 2).Left, Top:=Cells(r.Row, 2).Top, Width:=-1, Height:=-1)
With shpPic
.LockAspectRatio = msoTrue
If .Width > Columns(2).Width Then .Width = Columns(2).Width
Rows(r.Row).RowHeight = .Height
End With
End If
Else
Debug.Print fPath & r.Value & ".jpg not found"
End If
End If
Next r
Xexit:
'Application.ScreenUpdating = True
End Sub
Code is tested with makeshift images. May disable ScreenUpdatingas per actual condition.

Related

export certain worksheets using a userform

I would like to make exports based on the boxes I checked
therefore with a lot of help I build the following code
Private Sub CommandButton1_Click()
Dim xSht As Worksheet, xFileDlg As FileDialog, xFolder As String, xYesorNo, I, xNum As Integer
Dim xOutlookObj As Object, xEmailObj As Object, xUsedRng As Range, xArrShetts As Variant
Dim xPDFNameAddress As String, xStr As String, rngExp As Range, lastRng As Range
xArrShetts = sheetsArr(Me) 'do not forget the keep the sheetsArr function...
For I = 0 To UBound(xArrShetts)
On Error Resume Next
Set xSht = Application.ActiveWorkbook.Worksheets(xArrShetts(I))
If xSht.Name <> xArrShetts(I) Then
MsgBox "Worksheet no found, exit operation:" & vbCrLf & vbCrLf & xArrShetts(I), vbInformation, "Kutools for Excel"
Exit Sub
End If
Next
Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xFileDlg.Show = True Then
xFolder = xFileDlg.SelectedItems(1)
Else
MsgBox "You must specify a folder to save the PDF into." & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Must Specify Destination Folder"
Exit Sub
End If
'Check if file already exist
xYesorNo = MsgBox("If same name files exist in the destination folder, number suffix will be added to the file name automatically to distinguish the duplicates" & vbCrLf & vbCrLf & "Click Yes to continue, click No to cancel", _
vbYesNo + vbQuestion, "File Exists")
If xYesorNo <> vbYes Then Exit Sub
For I = 0 To UBound(xArrShetts)
Set xSht = Application.ActiveWorkbook.Worksheets(xArrShetts(I))
xStr = xFolder & "\" & xSht.Name & ".pdf"
xNum = 1
While Not (Dir(xStr, vbDirectory) = vbNullString)
xStr = xFolder & "\" & xSht.Name & "_" & xNum & ".pdf"
xNum = xNum + 1
Wend
Set xUsedRng = xSht.UsedRange
If Application.WorksheetFunction.CountA(xUsedRng.Cells) <> 0 Then
Set lastRng = xSht.Range("A" & xSht.Rows.Count).End(xlUp) 'determine the last cell in A:A
Set rngExp = xSht.Range(lastRng.Offset(-26), lastRng.Offset(, 7)) 'create the range to be exported as pdf
With xSht.PageSetup
.PaperSize = xlPaperA4
.PrintArea = rngExp.Address(0, 0)
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
rngExp.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xStr, Quality:=xlQualityStandard, IgnorePrintAreas:=False 'export the range, not the sheet
End If
xArrShetts(I) = xStr
Next
'Create Outlook email
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmailObj = xOutlookObj.CreateItem(0)
With xEmailObj
.Display
.To = ""
.cc = ""
.Subject = "????"
For I = 0 To UBound(xArrShetts)
.Attachments.Add xArrShetts(I)
Next
If .DisplayEmail = False Then
'.Send
End If
End With
End Sub
Private Function sheetsArr(uF As UserForm) As Variant
Dim c As MSForms.Control, strCBX As String, arrSh
For Each c In uF.Controls
If TypeOf c Is MSForms.CheckBox Then
If c.Value = True Then strCBX = strCBX & "," & c.Caption
End If
Next
sheetsArr = Split(Mid(strCBX, 2), ",") 'Mid(strCBX, 2) eliminates the first string character (",")
End Function
Private Sub CommandButton2_Click()
Unload basicUserform
End Sub
the problem is when I run the code no attachments show up or can be found in the destination map I choose earlier.
I also put the file here so you can see for yourself.:
https://easyupload.io/ufnmvr
I appreciate your help and time!
Added a check for valid range of 27 or more rows otherwise lastRng.Offset(-26) will fail and because On Error Resume Next was not cancelled with On Error Goto 0 it won't raise an error.
Private Sub CommandButton1_Click()
Dim xSht As Worksheet, xFileDlg As FileDialog
Dim xFolder As String, xYesorNo, I, xNum As Integer
Dim xOutlookObj As Object, xEmailObj As Object
Dim xUsedRng As Range, xArrShetts As Variant
Dim xPDFNameAddress As String, xStr As String
Dim rngExp As Range, lastRng As Range
xArrShetts = sheetsArr(Me) 'do not forget the keep the sheetsArr function...
If UBound(xArrShetts) < 0 Then
MsgBox "No sheets selected", vbExclamation
Exit Sub
End If
' check sheets exist
For I = 0 To UBound(xArrShetts)
On Error Resume Next
Set xSht = Application.ActiveWorkbook.Worksheets(xArrShetts(I))
If xSht.Name <> xArrShetts(I) Then
MsgBox "Worksheet no found, exit operation:" & vbCrLf & vbCrLf & _
xArrShetts(I), vbInformation
Exit Sub
End If
On Error GoTo 0
Next
Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xFileDlg.Show = True Then
xFolder = xFileDlg.SelectedItems(1)
Else
MsgBox "You must specify a folder to save the PDF into." & vbCrLf & vbCrLf & _
"Press OK to exit this macro.", vbCritical, "Must Specify Destination Folder"
Exit Sub
End If
'Check if filename already exist
xYesorNo = MsgBox("If same name files exist in the destination folder," & _
"number suffix will be added to the file name automatically " & _
"to distinguish the duplicates " & vbCrLf & vbCrLf & _
"Click Yes to continue, click No to cancel", _
vbYesNo + vbQuestion, "File Exists")
If xYesorNo <> vbYes Then Exit Sub
For I = 0 To UBound(xArrShetts)
Set xSht = Application.ActiveWorkbook.Worksheets(xArrShetts(I))
xStr = xFolder & "\" & xSht.Name & ".pdf"
xNum = 1
While Not (Dir(xStr, vbDirectory) = vbNullString)
xStr = xFolder & "\" & xSht.Name & "_" & xNum & ".pdf"
xNum = xNum + 1
Wend
Set xUsedRng = xSht.UsedRange
If Application.WorksheetFunction.CountA(xUsedRng.Cells) <> 0 Then
'determine the last cell in A:A
Set lastRng = xSht.Range("A" & xSht.Rows.Count).End(xlUp)
If lastRng.Row < 27 Then
MsgBox "Incorrect Start Row " & lastRng.Row, _
vbCritical, "ERROR on " & xSht.Name
Exit Sub
End If
'create the range to be exported as pdf
Set rngExp = xSht.Range(lastRng.Offset(-26), lastRng.Offset(, 7))
With xSht.PageSetup
.PaperSize = xlPaperA4
.PrintArea = rngExp.Address(0, 0)
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
'export the range, not the sheet
rngExp.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xStr, _
Quality:=xlQualityStandard, IgnorePrintAreas:=False
xArrShetts(I) = xStr
Else
' no file created
xArrShetts(I) = ""
End If
Next
'Create Outlook email
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmailObj = xOutlookObj.CreateItem(0)
With xEmailObj
.To = ""
.cc = ""
.Subject = "????"
For I = 0 To UBound(xArrShetts)
If Len(xArrShetts(I)) > 0 Then
.Attachments.Add xArrShetts(I)
End If
Next
.Display ' or ' Send
End With
End Sub

Screen alerts in Acrobat stopping VBA code

I have this VBA code that searches through PDF files on my computer. Here is the code:
Option Explicit
Sub FindTextInPDF()
Dim TextToFind As String
Dim PDFPath As String
Dim App As Object
Dim AVDoc As Object
Dim DS As Worksheet
Dim SS As Worksheet
Set DS = Sheets("Report")
Set SS = Sheets("Search Index")
Dim sslastrow As Long
Dim dslastrow As Long
Dim b As Integer
Dim J As Integer
With SS
sslastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
With DS
dslastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For b = 2 To dslastrow
PDFPath = "C:\Users\desposito\Documents\Temp\" &
Sheets("Report").Range("E" & b).Value & Sheets("Report").Range("B" &
b).Value & ".pdf"
If Dir(PDFPath) = "" Then
GoTo nextb
End If
If LCase(Right(PDFPath, 3)) <> "pdf" Then
GoTo nextb
End If
On Error Resume Next
Set App = CreateObject("AcroExch.App")
If Err.Number <> 0 Then
Set App = Nothing
GoTo nextb
End If
Set AVDoc = CreateObject("AcroExch.AVDoc")
If Err.Number <> 0 Then
Set AVDoc = Nothing
Set App = Nothing
GoTo nextb
End If
On Error GoTo 0
If AVDoc.Open(PDFPath, "") = True Then
AVDoc.BringToFront
Else
App.Exit
Set AVDoc = Nothing
Set App = Nothing
GoTo nextb
End If
For J = 2 To sslastrow
TextToFind = SS.Range("B" & J).Value
If AVDoc.FindText(TextToFind, False, False, True) = False Then
GoTo NextJ
Else:
DS.Range("Q" & b).Value = DS.Range("Q" & b).Value & TextToFind & ";"
& " "
End If
NextJ:
Next
AVDoc.Close True
App.Exit
Set AVDoc = Nothing
Set App = Nothing
nextb:
Next
End Sub
However, every 100ish files, I will get this notification:
"Reader has finished searching the document. No matches were found."
All I have to do is hit enter and then the code runs for another 10-30 minutes before I get the notification again. It seems to be randomly happening in the middle of searching through the document which is this part of the code:
For J = 2 To sslastrow
TextToFind = SS.Range("B" & J).Value
If AVDoc.FindText(TextToFind, False, False, True) = False Then
GoTo NextJ
Else:
DS.Range("Q" & b).Value = DS.Range("Q" & b).Value & TextToFind & ";"
& " "
End If
NextJ:
I looked into disabling screen alerts in acrobat, but it doesn't look like I can do that.

import multiple pictures into Excel and open file on another computer

I have managed to pull together some VBA code from other sources (many thanks) to create something that is about 80% complete. However when I send or open my spreadsheet on another computer my pictures do not appear (just a red X).
My research has lead me to use and insert the
ActiveSheet.Shapes.AddPicture method however I am unsure how to build this into my functioning code / where to place this. I have filenames in Column D which relate to the stored pictures from my folder. The pictures are loaded into Column C and this allworks perfectly, I have approx 550 jpeg files. However I cannot view the images once it's off my computer
My working code is:
Sub InsertPicsr1Reg()
Dim fPath As String, fName As String
Dim r As Range
Dim shp As Shape
Application.ScreenUpdating = False
fPath = "\Desktop\test workings\"
For Each r In Range("D2:D" & Cells(Rows.Count, 4).End(xlUp).Row)
On Error GoTo errHandler
If r.Value <> "" Then
With ActiveSheet.Pictures.Insert(fPath & r.Value)
.ShapeRange.LockAspectRatio = msoTrue
.Top = Cells(r.Row, 3).Top
.Left = Cells(r.Row, 3).Left
If .ShapeRange.Width > Columns(3).Width Then .ShapeRange _
.Width = Columns(3).Width
Rows(r.Row).RowHeight = .ShapeRange.Height
End With
End If
errHandler:
If Err.Number <> 0 Then
Debug.Print Err.Number & ", " & Err.Description & ", " & r.Value
On Error GoTo -1
End If
Next r
For Each shp In ActiveSheet.Shapes
shp.Placement = xlMoveAndSize
Next shp
Application.ScreenUpdating = True
End Sub
try this:
Sub InsertPicsr1Reg()
Dim fPath As String, fName As String
Dim r As Range
Dim shp As Shape
Application.ScreenUpdating = False
fPath = "\Desktop\test workings\"
For Each r In Range("D2:D" & Cells(Rows.Count, 4).End(xlUp).Row)
If r.Value <> "" Then
With ActiveSheet
.Shapes.AddPicture fPath & r.Value, _
msoFalse, msoTrue, _
.Cells(r.Row, 3).Left, _
.Cells(r.Row, 3).Top, _
.Columns(3).Width, _
.Rows(r.Row).Height
End With
end if
next
end sub

How to Insert Pictures into Comments of a cell by a given cell name

Thanks to Macromarc This Problem has been resolved
The problem i had with my code was it was only putting in the picture to a cell, and the picture was sized incorrectly. When i filtered my data the pictures always collapsed into each other and it did not look too great.
Below is the correct code that will work for you thanks to Macromarc
Private Sub GrabImagePasteIntoCell()
Const pictureNameColumn As String = "A" 'column where picture name is found
Const picturePasteColumn As String = "J" 'column where picture is to be pasted
Const pathForPicture As String = "M:\Users\Dan\Pictures\LabPics\" 'path of pictures
Dim pictureFile As String
Dim pictureName As String 'picture name
Dim lastPictureRow As Long 'last row in use where picture names are
Dim pictureRow As Long 'current picture row to be processed
Dim picturePasteCell As Range
pictureRow = 3 'starts from this row
On Error GoTo Err_Handler
Dim ws As Worksheet
Set ws = ActiveSheet 'replace with better qualification
lastPictureRow = ws.Cells(ws.Rows.Count, pictureNameColumn).End(xlUp).Row
'stop screen updates while macro is running
Application.ScreenUpdating = False
'loop till last picture row
Do While (pictureRow <= lastPictureRow)
pictureName = ws.Cells(pictureRow, pictureNameColumn).Value2
If (pictureName <> vbNullString) Then
'check if pic is present
pictureFile = pathForPicture & pictureName
Set picturePasteCell = ws.Cells(pictureRow, picturePasteColumn)
If (Dir(pictureFile & ".jpg") <> vbNullString) Then
insertPictureToComment pictureFile & ".jpg", picturePasteCell, 41, 41
ElseIf (Dir(pictureFile & ".png") <> vbNullString) Then
insertPictureToComment pictureFile & ".png", picturePasteCell, 100, 130
ElseIf (Dir(pictureFile & ".bmp") <> vbNullString) Then
insertPictureToComment pictureFile & ".bmp", picturePasteCell, 100, 130
Else
'picture name was there, but no such picture
picturePasteCell.Value2 = "No Picture Found"
End If
Else
'picture name cell was blank
End If
pictureRow = pictureRow + 1
Loop
On Error GoTo 0
Exit_Sub:
ws.Range("A10").Select
Application.ScreenUpdating = True
Exit Sub
Err_Handler:
MsgBox "Error encountered. " & Err.Description, vbCritical, "Error"
GoTo Exit_Sub
End Sub
The function below handles the insertion of generic images to a cell's comment shape:
Function insertPictureToComment(pictureFilePath As String, _
pictureRange As Range, _
commentHeight As Long, _
commentWidth As Long)
Dim picComment As Comment
If pictureRange.Comment Is Nothing Then
Set picComment = pictureRange.AddComment
Else
Set picComment = pictureRange.Comment
End If
With picComment.Shape
.Height = commentHeight
.Width = commentWidth
.LockAspectRatio = msoFalse
.Fill.UserPicture pictureFilePath
End With
End Function
I rewrote some of the other code, and refactored out a function.
Tested and it is basically working for me. Any questions ask:
Private Sub GrabImagePasteIntoCell()
Const pictureNameColumn As String = "A" 'column where picture name is found
Const picturePasteColumn As String = "J" 'column where picture is to be pasted
Const pathForPicture As String = "M:\Users\Dan\Pictures\LabPics\" 'path of pictures
Dim pictureFile As String
Dim pictureName As String 'picture name
Dim lastPictureRow As Long 'last row in use where picture names are
Dim pictureRow As Long 'current picture row to be processed
Dim picturePasteCell As Range
pictureRow = 3 'starts from this row
On Error GoTo Err_Handler
Dim ws As Worksheet
Set ws = ActiveSheet 'replace with better qualification
lastPictureRow = ws.Cells(ws.Rows.Count, pictureNameColumn).End(xlUp).Row
'stop screen updates while macro is running
Application.ScreenUpdating = False
'loop till last picture row
Do While (pictureRow <= lastPictureRow)
pictureName = ws.Cells(pictureRow, pictureNameColumn).Value2
If (pictureName <> vbNullString) Then
'check if pic is present
pictureFile = pathForPicture & pictureName
Set picturePasteCell = ws.Cells(pictureRow, picturePasteColumn)
If (Dir(pictureFile & ".jpg") <> vbNullString) Then
insertPictureToComment pictureFile & ".jpg", picturePasteCell, 41, 41
ElseIf (Dir(pictureFile & ".png") <> vbNullString) Then
insertPictureToComment pictureFile & ".png", picturePasteCell, 100, 130
ElseIf (Dir(pictureFile & ".bmp") <> vbNullString) Then
insertPictureToComment pictureFile & ".bmp", picturePasteCell, 100, 130
Else
'picture name was there, but no such picture
picturePasteCell.Value2 = "No Picture Found"
End If
Else
'picture name cell was blank
End If
pictureRow = pictureRow + 1
Loop
On Error GoTo 0
Exit_Sub:
ws.Range("A10").Select
Application.ScreenUpdating = True
Exit Sub
Err_Handler:
MsgBox "Error encountered. " & Err.Description, vbCritical, "Error"
GoTo Exit_Sub
End Sub
The function below handles the insertion of generic images to a cell's comment shape:
Function insertPictureToComment(pictureFilePath As String, _
pictureRange As Range, _
commentHeight As Long, _
commentWidth As Long)
Dim picComment As Comment
If pictureRange.Comment Is Nothing Then
Set picComment = pictureRange.AddComment
Else
Set picComment = pictureRange.Comment
End If
With picComment.Shape
.Height = commentHeight
.Width = commentWidth
.LockAspectRatio = msoFalse
.Fill.UserPicture pictureFilePath
End With
End Function

Create Hyperlink for row each entry in Excel Sheet but just in specific columns

In the attached code, I am looping through all the Excel files in a folder and searching for a keyword. I then extract the file name, sheet number, cell number and row data and place that information into a newly created spreadsheet called "Summary". How do I hyperlink just the worksheet # and cell # columns (Columns B and C) to point to the exact file, page, cell where the newly created row entry came from?
Here is a snippet of my code:
Sub SearchFolders()
'UpdatebySUPERtoolsforExcel2016
...
Dim xOut As Worksheet
Dim xWb As Workbook
Dim xWk As Worksheet
Dim xRow As Long
Dim xFound As Range
Dim xStrAddress As String
Dim xCount As Long
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
xFileDialog.AllowMultiSelect = False
xFileDialog.Title = "Select a forlder"
If xFileDialog.Show = -1 Then
xStrPath = xFileDialog.SelectedItems(1)
End If
...
xUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
Set xOut = wsReport
xRow = 1
With xOut
.Cells(xRow, 1) = "Workbook"
.Cells(xRow, 2) = "Worksheet"
.Cells(xRow, 3) = "Cell"
.Cells(xRow, 4) = "Test"
...
Set xFso = CreateObject("Scripting.FileSystemObject")
Set xFld = xFso.GetFolder(xStrPath)
xStrFile = Dir(xStrPath & "\*.xlsx")
Do While xStrFile <> ""
Set xWb = Workbooks.Open(Filename:=xStrPath & "\" & xStrFile, UpdateLinks:=0, ReadOnly:=True, AddToMRU:=False)
For Each xWk In xWb.Worksheets
Set xFound = xWk.UsedRange.Find(xStrSearch, LookIn:=xlValues)
If Not xFound Is Nothing Then
xStrAddress = xFound.Address
End If
Do
If xFound Is Nothing Then
Exit Do
Else
xCount = xCount + 1
xRow = xRow + 1
.Cells(xRow, 1) = xWb.Name
.Cells(xRow, 2) = xWk.Name
.Cells(xRow, 3) = xFound.Address
WriteDetails rCellwsReport, xFound
End If
Set xFound = xWk.Cells.FindNext(After:=xFound)
Loop While xStrAddress <> xFound.Address
Next
xWb.Close (False)
xStrFile = Dir
Loop
.Columns("A:I").EntireColumn.AutoFit
.Range("A1:A" & xCount + 1).Rows.EntireRow.AutoFit
End With
MsgBox xCount & "cells have been found", , "SUPERtools for Excel"
ExitHandler:
Set xOut = Nothing
...
Application.ScreenUpdating = xUpdate
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Private Sub WriteDetails(ByRef xReceiver As Range, ByRef xDonor As Range)
xReceiver.Value = xDonor.Parent.Name
xReceiver.Offset(, 1).Value = xDonor.Address
xDonor.EntireRow.Resize(, 100).Copy xReceiver.Offset(, 2)
Set xReceiver = xReceiver.Offset(1)
End Sub
To create a hyperlink to an external workbook/worksheet/cell you need to understand how the link forms
See this example
Let's say you have a file Joe.Xlsx in C:\. And let's assume that it has a worksheet called Sheet1 and you want to hyperlink to cell A1 of that sheet.
So in your current workbook, you will type
=HYPERLINK("[C:\Joe.xlsx]Sheet1!A1","CLICK HERE")
So if you break it, it will look like this.
Dim FileName As String
Dim SheetName As String
Dim CellAddress As String
FileName = "C:\Joe.xlsx"
SheetName = "Sheet1"
CellAddress = "A1"
If InStr(1, SheetName, " ") Then SheetName = "'" & SheetName & "'"
Range("A1").Formula = "=HYPERLINK(" & Chr(34) & "[" & _
FileName & _
"]" & _
SheetName & _
"!" & _
CellAddress & _
Chr(34) & "," & Chr(34) & _
"CLICK HERE" & Chr(34) & ")"
Simply use this in your code in a loop and create the hyperlinks

Resources