View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Terry Pinnell[_4_] Terry Pinnell[_4_] is offline
external usenet poster
 
Posts: 192
Default Pasting text into VBA macro?

GS wrote:

Typo...

Function Get_FileToOpen$(Optional FileTypes$)
If FileTypes = "" Then FileTypes = "All Files ""*.*"", *.*"
Dim vFile
vFile = Application.GetOpenFilename(FileTypes)
Get_FileToOpen = IIf(vFile = False, "", vFile)
End Function


Thanks Garry. I'm using your edited version below:

Sub InsertPictureFromFile()
'Inserts picture-from-file at the active cell
Dim sFile$

sFile = Get_FileToOpen: If sFile = "" Then Exit Sub
ActiveSheet.Pictures.Insert(sFile).Select
Selection.ShapeRange.ScaleHeight 0.85, msoFalse, msoScaleFromTopLeft
'Assumes the follow 'custom' toolbar exists
Application.CommandBars("Format Object").Visible = False
Rows("27:27").Select
End Sub

Function Get_FileToOpen$(Optional FileTypes$)
If FileTypes = "" Then FileTypes = "All Files ""*.*"", *.*"
Dim vFile
vFile = Application.GetOpenFilename(FileTypes)
Get_FileToOpen = IIf(vFile = False, "", vFile)
End Function

But instead of immediately pasting the image from the text on the
clipboard (into fixed cell A30) it brings up a browser dialog.

I'm happy enough using my fully working macro below (based on my
trial/error adaptations from killme2008's), but I'm keen to know why
(unlike yours) it fails when placed outside PERSNAL.xlsb.

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

Terry, East Grinstead, UK