excel - 如何旋转图像并将其移动到特定位置?
问题描述
我正在尝试上传图片,然后将其旋转并将其移动到特定位置,但我似乎无法让它旋转。我有这个代码是因为我想将图片与文档一起保存。
Sub tyh()
ActiveSheet.Shapes.AddPicture _
Filename:="C:\Users\dovi.dovi-PC\Desktop\ads bh\IMG-7042.jpg", _
linktofile:=msoFalse, savewithdocument:=msoCTrue, _
Left:=1200, Top:=0, Width:=350, Height:=604
End Sub
解决方案
宏记录器在这里真的可以帮助您 - 上传图片并查看它为旋转生成的代码。我的是这样的:
ActiveSheet.Shapes.Range(Array("Picture 1")).Select
Selection.ShapeRange.IncrementRotation 90
当然,应该避免使用 theSelection
和 the ActiveSheet~.Select
,但这取决于您的代码。这是在不选择的情况下旋转图片的好方法:
Sub TestMe()
KillAllShapes Worksheets(1)
ThisWorkbook.Worksheets(1).Pictures.Insert ("C:\SomePic.jpg")
Dim myShape As Shape
Set myShape = Worksheets(1).Shapes(1)
With myShape
.Top = Range("B5").Top
.Left = Range("B5").Left
.IncrementRotation 180 'or 90
End With
End Sub
Sub KillAllShapes(wks As Worksheet)
Dim sh As Shape
For Each sh In wks.Shapes
sh.Delete
Next
End Sub
ShapeRange.IncrementRotation 文档中的这个看起来不错:
Set myDocument = Worksheets(1)
With myDocument.Shapes(1).Duplicate
.Fill.PresetTextured msoTextureGranite
.IncrementLeft 70
.IncrementTop -50
.IncrementRotation 30
End With
推荐阅读
- python - 过滤字典以返回某些键
- apache - 重定向后 Apache RewtireRule 不保存 URL
- javascript - 尝试发送请求时出现“405 方法不允许”错误。通过 JS 获取 API 到 PHP 文件
- laravel-5.8 - 创建迁移时错误地形成了外键约束
- android - 申请报告需要很长时间才能更新
- python - Python 集成测试:使用 paramiko 伪造一个 ssh 服务器,并记录给它的命令
- angular - 如何在另一个 Angular 应用程序中导入 Angular Web 组件
- node.js - 如何将多个查询值添加到 url
- java - 如何链接 reactor 订阅者
- linux - 为什么 Centos 7 的 Docker 文件不支持 yum 命令