SOLVED

Macro to set where data should start

Copper Contributor

I have the following macro which does the following:

 

  1. Get the file names from a folder on Windows
  2. Combines the name with the folder name 
  3. Hyperlinks the conjoined names 

 

How it looks in the table:

 

DrishM_0-1608644792706.png

 

My code is as follows:

 

Sub Combined()

'Gets file names

Dim xFSO As Object
Dim xFolder As Object
Dim xFile As Object
Dim xFiDialog As FileDialog
Dim xPath As String
Dim i As Integer
Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFiDialog.Show = -1 Then
xPath = xFiDialog.SelectedItems(1)
End If
Set xFiDialog = Nothing
If xPath = "" Then Exit Sub
Set xFSO = CreateObject("Scripting.FileSystemObject")
Set xFolder = xFSO.GetFolder(xPath)
For Each xFile In xFolder.Files
i = i + 1
ActiveSheet.Hyperlinks.Add Cells(i, 3), xFile.Path, , , xFile.Name
Next

'Adds the name to folder

Dim x As Integer

For x = 1 To 4
Cells(x, 5).Value = Cells(x, 4) & "\" & Cells(x, 3)
Next x

'Converts each text hyperlink selected into a working hyperlink

Dim xCell As Range

For Each xCell In Selection
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
Next xCell

End Sub

 

Is it possible to add some code that will stop the data from outputting to C1 and rather start at C2?

 

Thanks.

 

1 Reply
best response confirmed by DrishM (Copper Contributor)
Solution

@DrishM 

It looks like you need to define the i integer. Add this after the Dim i as Integer line

i = 2

 

1 best response

Accepted Solutions
best response confirmed by DrishM (Copper Contributor)
Solution

@DrishM 

It looks like you need to define the i integer. Add this after the Dim i as Integer line

i = 2

 

View solution in original post