2016-02-17 28 views
1

我想將PowerPoint演示文稿圖形中的鏈接轉移到另一個文件夾。找到一些代碼,但它只選擇特定的文件來改變鏈接,而不是我不能使用的文件夾,因爲我的PowerPoint鏈接到兩個不同的Excel文件(在同一個文件夾中)。更改Powerpoint鏈接到不同的文件夾

Sub M1() 
Dim sld As Slide 
Dim sh As Shape 
Dim strNms As String 
Dim intI As Integer 
Dim strNewPath 
Dim ExcelFile 
Dim exl As Object 
Set exl = CreateObject("Excel.Application") 

'Open a dialog box to promt for the new source file. 
ExcelFile = exl.Application.GetOpenFilename(, , "Select Excel File") 
For Each sld In ActivePresentation.aSlides 
    For Each sh In sld.Shapes 
     If sh.Type = msoLinkedOLEObject Then 
      With sh.LinkFormat 
       strNms = .SourceFullName 
       intI = InStr(1, strNms, "!") 
       strNewPath = ExcelFile & Mid(strNms, intI, Len(strNms) - intI + 1) 
       .SourceFullName = strNewPath 
      End With 
     End If 
    Next sh 
Next sld 
End Sub 

回答

1

看一看這裏的代碼:

批量搜索和替換的超鏈接,OLE鏈接,影片鏈接和聲音鏈接 http://www.pptfaq.com/FAQ00773_Batch_Search_and_Replace_for_Hyperlinks-_OLE_links-_movie_links_and_sound_links.htm

它會告訴你,例如,更換鏈接文件的路徑(即不同文件夾名稱),但不更改鏈接文件的名稱。

重要提示:在運行代碼之前,您必須將文件重新鏈接到您嘗試重新鏈接TO的文件夾中。如果你改變一個鏈接指向一個不存在的文件,PPT會對你微笑,並說「OK」,但它不會改變任何東西。

相關問題