返回列表 上一主題 發帖

[分享] (已解決)請問大大,如果EXCEL 2003轉換至2010,原程式要如何修正?

[分享] (已解決)請問大大,如果EXCEL 2003轉換至2010,原程式要如何修正?

本帖最後由 cmo140497 於 2012-2-20 11:59 編輯

Dear 大大 :
目前小弟遇到一個問題,公司電腦轉換至office 2010後,原excel 2003 巨集,卻無法執行,尤其在插入圖片部份,該如何解決?另外還有哪些的差異,須注意的,實在感謝!

感謝大大的指導,但在picture.insert 的語法,在2010年版似乎引用上是否有所不同,感謝!

[attach]9607[/attach]

2010 get SINF_20120215.rar (15.41 KB)

如果活頁簿包含您要保留的巨集,請按一下 [.xlsm]。
如果活頁簿包含您要保留的巨集,而您要將活頁簿儲存為巨集,請按一下 [.xltm]。
詳細請參考
http://office.microsoft.com/zh-tw/excel-help/HA010342994.aspx#BM4
將活頁簿轉換為 Excel 2010 檔案格式

TOP

謝謝大大的指導,但在picture.insert的部份還是有問題,謝謝!

TOP

回復 1# cmo140497


    [url]http://chijanzen.net/wp/?p=495[/url]
學海無涯_不恥下問

TOP

感謝版主的指導,但小弟不管怎麼試,這個程式似乎不為所動,謝謝!

TOP

我有下載檔案在2003中執行~ 無任何反應~

樓主確定file一開始就是可以被執行的嘛???
學習才能提升自己

TOP

回復 5# cmo140497
你的目的為何我不知道,但要新增圖片只要改成以下流程即可
  1. Sub STARTGETSINF()
  2. Dim Fs As Object, E, i As Integer, P, ii As Integer
  3.     Dim xlPath As String
  4.     Dim myWb As Workbook
  5.     Dim myFileName As String
  6. Cells.Clear
  7. ActiveWindow.Zoom = 75
  8. Rows("2:9999").EntireRow.AutoFit
  9. Columns("B:Y").ColumnWidth = 2

  10. With Application.FileDialog(msoFileDialogFolderPicker)
  11.         .AllowMultiSelect = False
  12.         .InitialFileName = "D:\Export\SINF\"
  13.         .Show
  14.         If .SelectedItems.Count = 0 Then Exit Sub
  15.         xlPath = .SelectedItems(1)
  16. End With

  17. With CreateObject("Scripting.FileSystemObject").GetFolder(xlPath)
  18.         i = 1
  19.         For Each E In .SubFolders
  20.             If i > ActiveWorkbook.Sheets.Count Then
  21.                 Sheets.Add(, Sheets(Sheets.Count)).Name = E.Name
  22.             Else
  23.                 Sheets(i).Name = E.Name
  24.             End If
  25.             ii = 2
  26.            For Each P In E.Files
  27.               If InStr(UCase(P.Name), ".JPG") Then
  28.                 ActiveWindow.Zoom = 75
  29.                                                 
  30.                 With Sheets(i).Cells(ii, 2).Select                         '設定圖片欄位大小
  31.                      With Selection
  32.                       .RowHeight = 60
  33.                       .ColumnWidth = 9.5
  34.                       .WrapText = True
  35.                      End With
  36.                      
  37.                       t = Cells(ii, 2).Top + Cells(ii, 2).Height * 0.1  '圖片上位置
  38.                       l = Cells(ii, 2).Left + Cells(ii, 2).Width * 0.1 '圖片左位置
  39.                       w = 50                                          '圖片縮小50%寬度
  40.                       h = 50                                         '圖片縮小50%高度

  41.                   With Sheets(i).Shapes.AddPicture(P, True, True, l, t, w, h) 'B欄插入圖片
  42.                       .Placement = xlMove                        '圖片大小隨儲存格位置而改變

  43.                          With Sheets(i)                                    'A欄插入圖片名稱
  44.                            '.Cells(ii, 1) = P.Name                          '圖片檔案名稱
  45.                            .Cells(ii, 1) = P                              '圖片檔案完整路徑
  46.                          End With
  47.                   End With
  48.                 End With
  49.                 ii = ii + 1                                                '一次跳的欄位數
  50.               End If
  51.             Next
  52.         Next
  53.     End With
  54.    
  55. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 7# Hsieh

感謝版主的指正,其實這幾段程式也是先前請版主指正拼湊出來的,小弟不是很懂其中的意思,剛才的程式試run了一下,圖片一直重疊,debug後,發現sheet(i)沒有累加,現已經ok,2003年版的excel
picture,insert( ),無法延用至2010年版,小弟現在了解了,實在感謝!
  1. Sub STARTGETSINF()
  2. Dim Fs As Object, E, i As Integer, P, ii As Integer
  3.     Dim xlPath As String
  4.     Dim myWb As Workbook
  5.     Dim myFileName As String
  6. Cells.Clear
  7. ActiveWindow.Zoom = 75
  8. Rows("2:9999").EntireRow.AutoFit
  9. Columns("B:Y").ColumnWidth = 2

  10. With Application.FileDialog(msoFileDialogFolderPicker)
  11.         .AllowMultiSelect = False
  12.         .InitialFileName = "D:\Export\SINF\"
  13.         .Show
  14.         If .SelectedItems.Count = 0 Then Exit Sub
  15.         xlPath = .SelectedItems(1)
  16. End With

  17. With CreateObject("Scripting.FileSystemObject").GetFolder(xlPath)
  18.         i = 1
  19.         For Each E In .SubFolders
  20.             If i > ActiveWorkbook.Sheets.Count Then
  21.                 Sheets.Add(, Sheets(Sheets.Count)).Name = E.Name
  22.             Else
  23.                 Sheets(i).Name = E.Name
  24.             End If
  25.             ii = 2
  26.            For Each P In E.Files
  27.               If InStr(UCase(P.Name), ".JPG") Then
  28.                 ActiveWindow.Zoom = 75
  29.                                                 
  30.                 With Sheets(i).Cells(ii, 2).Select                         '設定圖片欄位大小
  31.                      With Selection
  32.                       .RowHeight = 60
  33.                       .ColumnWidth = 9.5
  34.                       .WrapText = True
  35.                      End With
  36.                      
  37.                       t = Cells(ii, 2).Top + Cells(ii, 2).Height * 0.1  '圖片上位置
  38.                       l = Cells(ii, 2).Left + Cells(ii, 2).Width * 0.1 '圖片左位置
  39.                       w = 50                                          '圖片縮小50%寬度
  40.                       h = 50                                         '圖片縮小50%高度

  41.                   With Sheets(i).Shapes.AddPicture(P, True, True, l, t, w, h) 'B欄插入圖片
  42.                       .Placement = xlMove                        '圖片大小隨儲存格位置而改變

  43.                          With Sheets(i)                                    'A欄插入圖片名稱
  44.                            '.Cells(ii, 1) = P.Name                          '圖片檔案名稱
  45.                            .Cells(ii, 1) = P                              '圖片檔案完整路徑
  46.                          End With
  47.                   End With
  48.                 End With
  49.                 ii = ii + 1                                                '一次跳的欄位數
  50.               End If
  51.             Next
  52.         [b][color=Red]i = i + 1[/color][/b]        Next
  53.     End With
  54.    
  55. End Sub
複製代碼

TOP

        靜思自在 : 靜坐常恩己過、閒談莫論人非。
返回列表 上一主題