2016-09-22 4 views
0

私は画像と2つのボタンがあるワークシートを持っています。 (請求書) 私はワークシートをイメージと共にコピーしたいが、2つのボタンを使わずに新しいブックの新しいシートにコピーしたいのですが、私はそれをVBAマクロでやりたいと思います。 私は通常のコピーコマンドでそれを行い、2つのボタンに対して追加の削除コマンドを使用します。vba excel:画像付きのワークシートをボタンなしでコピーする方法

私は確かに簡単な方法があります。 私はこれを試してみました...

Application.CopyObjectsWithCells = False 
Sheets("invoice").Select 
Sheets("invoice").Move After:=Workbooks("invoices").Sheets(1) 
Application.CopyObjectsWithCells = True 

これらは、ボタンを失ったが、画像もなくなっています。しかし私はイメージを保持したいと思います。

私はあなたがこれで私を助けることを願っています。

ありがとうございます。

答えて

0

説明は以下のコード内のコメントには、次のとおりです。

Option Explicit 

Sub CopySheet_WO_Btn() 

Dim newWB      As Workbook 
Dim ShtOrig      As Worksheet 

Dim Obj       As OLEObject 
Dim PicShape     As Shape 
Dim PicLeft      As Double 
Dim PicTop      As Double 

Set ShtOrig = ThisWorkbook.Sheets("invoice") 

' loop through all objects in "invoice" sheet 
For Each Obj In ShtOrig.OLEObjects 

    ' if OLE Object is type CommanButton make it Un-Visible (not to copy with the sheet) 
    If Obj.progID = "Forms.CommandButton.1" Then 
     Obj.Visible = False 
    End If 

Next Obj 

Set newWB = Workbooks.Add(xlWBATWorksheet) 
ShtOrig.Copy newWB.Sheets(1) 

' loop through all shapes in "invoice" sheet and copy the pictures 
For Each PicShape In ShtOrig.Shapes 
    If PicShape.Name = "Picture 1" Then 
     PicLeft = PicShape.Left 
     PicTop = PicShape.Top 
     PicShape.Copy 

     newWB.Sheets(1).Paste 
     Selection.ShapeRange.Left = PicLeft 
     Selection.ShapeRange.Top = PicTop 
    End If 
Next PicShape 

' loop again and return the CommandButtons to be Visible in "invoice" sheet 
For Each Obj In ShtOrig.OLEObjects 
    Obj.Visible = True 
Next Obj 

End Sub 
+0

おかげであなたの助けのためにたくさん!これは私の小さな請求書には多すぎますが、あなたは私に素晴らしいアイデアをくれました。私はあなたの助けを借りて、ボタンを非表示にする方法を見つけ、ワークブックを新しいワークブックにコピーし、元の請求書のボタンをもう一度表示させるようにしました。ありがとうございました –

+0

大きすぎるとはどういう意味ですか? –

関連する問題