View Single Post
  #6   Report Post  
Old February 8th 18, 10:30 PM posted to microsoft.public.excel.misc
Terry Pinnell[_4_] Terry Pinnell[_4_] is offline
external usenet poster
 
First recorded activity by ExcelBanter: Aug 2015
Posts: 144
Default Pasting text into VBA macro?

Terry Pinnell wrote:

GS wrote:

This recorded VBA macro inserts a specific picture into A22 and resizes
it to 85% of its original size.

Sub InsertPicture_Gf4()
'
Range("A30").Select
ActiveSheet.Pictures.Insert( _

"C:\Users\terry\Dropbox\FinishedWalks\20170809Day0 2Trevone-Porthcothan-J-u502-red-m8.8-Gf4-Elev.jpg"
_
).Select
Selection.ShapeRange.ScaleHeight 0.85, msoFalse, msoScaleFromTopLeft
Application.CommandBars("Format Object").Visible = False
Rows("27:27").Select
End Sub

But how can I edit that so that the filename
"C:\Users\terry\Dropbox\FinishedWalks\20170809Day0 2Trevone-Porthcothan-J-u502-red-m8.8-Gf4-Elev.jpg"
is replaced by whatever text is on the clipboard please?

Terry, East Grinstead, UK


I'm curious how the file path gets in the ClipBoard...


Hi Garry,

From a Macro Express Pro macro. I use a command to copy a variable
called FullTrackName (derived in earlier stages) to the clipboard.

I'm struggling to apply killme2008's advice. And would welcome some
further advice please. How exactly do I insert that specified JPG
picture at cell A30 of my (active) worksheet, TrackData-New.xlsm?

I was assuming it would be a relatively simple matter of replacing that
full filename with a line or two of code that would in effect PASTE it
into the simple macro I posted, and hence perform the insertion.


Terry, East Grinstead, UK


I finally got this working:

Sub InsertPicture_Gf4()
'
Dim MyData As DataObject
Dim strClip As String

Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText
Range("A30").Select
ActiveSheet.Pictures.Insert(strClip).Select
Selection.ShapeRange.ScaleHeight 0.85, msoFalse, msoScaleFromTopLeft
Application.CommandBars("Format Object").Visible = False
Rows("27:27").Select
End Sub

HOWEVER, it will only work if I place it in Personal.xlsb. If I put it
in the worksheet in which I want to work I get this error:
"Compile error:
User-defined type not defined".

I did observe the obscure instruction I had found, namely that for this
to work you must "Have at least one UserForm in your project".
https://www.dropbox.com/s/clwdmrz4z1...rking.jpg?dl=0

Anyone know the reason for this failure please?

Terry, East Grinstead, UK