2

I have a source excel workbook (XLSM format) that has sheets containing images. These sheets are programatically copied into another(target) workbook (XLSM) using VB.NET late binding. After all the copy is done i save the workbook and launch it. In the opened excel workbook I see the error message 'The image part with relationship ID rId1 was not found in the file' at all places where the images are placed. All the operations are done in the client machine no server side code available.

Interestingly this issue doesn't occur in Excel 2013 and it displays the images properly issue is observed only in 2010 and 2007. Is this a know bug in Excel 2010 and 2007 if yes can any one provide me the official link to the ticket so that i can track the issue and get the Hot fix once it is available.

 Dim SourceExcelWorkbook As Excel.Workbook = Nothing
    Dim TargetExcelWorkbook As Excel.Workbook = Nothing
    Dim TargetExcelSheets As Excel.Sheets = Nothing
    Dim SourceExcelSheets As Excel.Sheets = Nothing
    Dim CopyWorkSheet As Excel.Worksheet = Nothing

    Dim XLApp As New Excel.Application
    XLApp.Visible = False
    XLApp.DisplayAlerts = False
    XLApp.ScreenUpdating = False

    Dim pobjExcelWorkbooks As Excel.Workbooks = XLApp.Workbooks

    SourceExcelWorkbook = pobjExcelWorkbooks.Open("source file path")
    TargetExcelWorkbook = pobjExcelWorkbooks.Open("target file path")

    TargetExcelSheets = TargetExcelWorkbook.Worksheets
    SourceExcelSheets = SourceExcelWorkbook.Worksheets

    Dim OriginalSheetCount As Integer = TargetExcelSheets.Count
    Dim SheetCount As Integer = OriginalSheetCount
    Dim SheetsToBeCopiedCount As Integer = SourceExcelSheets.Count

    While SheetsToBeCopiedCount > 0
        Dim lobjAfterSheet As Object = TargetExcelSheets.Item(SheetCount)
        CopyWorkSheet = SourceExcelSheets.Item(1)
        CopyWorkSheet.Move(After:=lobjAfterSheet)
        SheetCount = SheetCount + 1
        TargetExcelWorkbook.Save()
        SheetsToBeCopiedCount = SheetsToBeCopiedCount - 1
    End While

    TargetExcelWorkbook.Save()
teja_98666
  • 85
  • 1
  • 11
  • That seems more like a googling-task than a programming question. :) Maybe you can show us your code or what you have tried so far. – Tom K. Sep 09 '15 at 07:02
  • @Tom I included the sample code. The source excel workbook has the images. Once the above code is executed and i open the target workbook i see the images error. Any suggestions? – teja_98666 Sep 09 '15 at 13:37
  • Unfortunately I dont have an older excel-version to test this, but my first guess would be the `.move`. Maybe excel just creates a reference to your existing workbook/sheet instead of copying the picture. – Tom K. Sep 09 '15 at 14:57
  • @Tom Do you have any work around for "Move" function ? I cant use Copy as i have have links to other workbooks in the source workbook which might be broken if i copy them to target workbook. – teja_98666 Sep 10 '15 at 05:28
  • Did you use `.copy` or is this only an assumption? For what I'm reading this should be the right call. – Tom K. Sep 10 '15 at 07:11
  • And I found this: http://stackoverflow.com/questions/941559/use-vba-to-copy-an-image-from-headers-footers-of-one-sheet-to-another – Tom K. Sep 10 '15 at 07:19
  • I tried `.Copy` and it works but the links that we use broke and i cannot get the links back working. – teja_98666 Sep 10 '15 at 12:48
  • The below link says that this is a bug and fixed in 2013 but i need a official link from Microsoft that approves this. [link]http://www.spreadsheet1.com/excel-vba-bugs.html – teja_98666 Sep 10 '15 at 12:49
  • Well, I think this is your task now. (; – Tom K. Sep 10 '15 at 12:51

0 Answers0