アプリ版:「スタンプのみでお礼する」機能のリリースについて

ASPからEXCELファイルを作成し、セルに画像を貼り付け、更に貼り付けられた画像の位置を調整したいのですが

Dim objExcel

fso = CreateObject("Scripting.FileSystemObject")
Set objExcel = Server.CreateObject("Excel.Application")
Set objExcelBook = objExcel.ActiveWorkbook
Set objExcelSheets = objExcelBook.Worksheets

If (fso.FileExists(Server.MapPath("【パス付画像のファイル名】"))) Then
objExcelSheet.Cells(3, 18).Select
objExcelSheet.Pictures.Insert(server.mappath("【パス付画像のファイル名】")).Select
End If

これで指定のセルに指定の画像を貼り付けることはできましたが、画像の位置を調整するコトができません。
EXCELのマクロからコードを調べたところ

Selection.ShapeRange.IncrementLeft 12.75
Selection.ShapeRange.IncrementTop 7.5

という記述が書いてあったのですが、そのままASPで使えそうにはありません。
ASPでEXCELに貼り付けた画像の位置を変更する記述を教えてください。
よろしくお願いします。

A 回答 (1件)

これでどうでしょう。


#インデント部分は全角スペースですので、コピペする時は注意して下さい。

Dim fso, objExcel, objExcelBooks, objExcelSheets, objShapes

Set fso = CreateObject("Scripting.FileSystemObject")
Set objExcel = Server.CreateObject("Excel.Application")
Set objExcelBooks = objExcel.Workbooks

Call objExcelBooks.Add
Set objExcelSheets = objExcelBooks(1).Sheets

If (fso.FileExists(Server.MapPath("sample.jpg"))) Then
  Call objExcelSheets(1).Activate
  objExcelSheets(1).Cells(3, 18).Select
  objExcelSheets(1).Pictures.Insert(Server.MapPath("sample.jpg"))
  Set objShapes = objExcelSheets(1).Shapes
  Call objShapes(1).IncrementLeft(12.75)
  Call objShapes(1).IncrementTop(7.5)
  Set objShapes = Nothing
End If
Call objExcelBooks(1).SaveAs(Server.MapPath("sample.xls"))
Call objExcelBooks.Close
Call objExcel.Quit

Set objExcelSheets = Nothing
Set objExcelBooks = Nothing
Set objExcel = Nothing
Set fso = Nothing
    • good
    • 1

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!