在EXCEL建立目录,如何批量链接另外一个文件夹里面的文件,
Sub Main() ? ?Dim fd As FileDialog ? ?Set fd = Application。FileDialog(msoFileDialogFilePicker) ? ?Dim vrtSelectedItem As Variant ? ?Dim Counter As Integer ? ?Counter = 1 ? ?With fd ? ? ? ?If 。 Show = -1 Then ? ? ? ? ? ?For Each vrtSelectedItem In 。SelectedItems ? ? ? ?Set curCell = Works...全部
Sub Main() ? ?Dim fd As FileDialog ? ?Set fd = Application。FileDialog(msoFileDialogFilePicker) ? ?Dim vrtSelectedItem As Variant ? ?Dim Counter As Integer ? ?Counter = 1 ? ?With fd ? ? ? ?If 。
Show = -1 Then ? ? ? ? ? ?For Each vrtSelectedItem In 。SelectedItems ? ? ? ?Set curCell = Worksheets("Sheet1")。
Cells(Counter, 1) ? ? ? ?curCell。Value = vrtSelectedItem ? ? ? ?curCell。Select ? ? ? ?ActiveSheet。
Hyperlinks。Add Anchor:=Selection, Address:=vrtSelectedItem, TextToDisplay:=vrtSelectedItem ? ? ? ? ? ?Counter = Counter 1 ? ? ? ? ? ?Next vrtSelectedItem ? ? ? ?Else ? ? ? ?End If ? ?End With ? ?Set fd = Nothing End Sub 运行以上代码不需要手动建立目录,可以Sheet1中直接显示选中的目录内文件名,并自动建立超级链接。
Sub Main() Dim fd As FileDialog Set fd = Application。FileDialog(msoFileDialogFilePicker) Dim vrtSelectedItem As Variant Dim Counter As Integer Counter = Sheets("Sheet1")。
Cells(65536, 1)。End(xlUp)。Row 1 With fd If 。Show = -1 Then For Each vrtSelectedItem In 。
SelectedItems Set curCell = Worksheets("Sheet1")。Cells(Counter, 1) curCell。Value = vrtSelectedItem curCell。
Select ActiveSheet。Hyperlinks。Add Anchor:=Selection, Address:=vrtSelectedItem, TextToDisplay:=vrtSelectedItem Counter = Counter 1 Next vrtSelectedItem Else End If End With Set fd = NothingEnd Sub 追答 : 不需手动建立目录,运行程序,选择需要建立的文件即可。
需添加目录,再次运行程序即可。不用的直接删除那一行。 追答 : 比你陈述的效果更好。你试试。 。收起