I have a script that will run on GPO on Windows Server 2012.
It's pretty simple stuff, but I cannot fathom how to add a hyperlink around an image! I have:
objSelection.InlineShapes.AddPicture "linktoimage.html"
This works a dream, I can see the image and there is no issue. But how do I add a hyperlink to this image so that when folks click on it they are taken to my desired hyperlink location. I know adding an image is simply a line of code, hoping for same for adding a hyperlink.
I am not doing this in excel or anything of the kind, just Notepad++
Assuming this is about Word, you need to save a reference the shape you just created and then use that reference as an argument to Document.Hyperlinks.Add
Option Explicit
Sub LinkImageTest()
Dim oSelection As Selection
Dim oDocument As Document
Dim oShape As InlineShape
Set oSelection = Application.Selection
Set oDocument = oSelection.Document
Set oShape = oSelection.InlineShapes.AddPicture("https://yt3.ggpht.com/-Pde_zs2tuj0/AAAAAAAAAAI/AAAAAAAAAAA/iBq9KSwTTLk/s88-c-k-no-mo-rj-c0xffffff/photo.jpg")
oDocument.Hyperlinks.Add oShape, "http://www.microsoft.com"
End Sub
Related
I'm sorry if I can't explain this very well. Language barrier and all that. Might explain why I wasn't able to google a solution... Anyway.
I'm trying to make an interactive Powerpoint where in the first slide the user writes their name in an ActiveX textbox and the name then repeats in several other slides. Because the name would be in the middle of different texts my solution was to add a placeholder word that would then be replaced with the textbox value. I was able to Frankenstein a code that replaces one name with another that works well enough but I can't get the textbox to work with it. Best I can do is replace the placeholder name with some variation of TextBox1.Value and while I know what causes that issue I can't work out a solution.
Not sure if it makes a difference but the plan is to add some sort of "OK" button next to the active textbox that runs the macro.
Sub Findandreplace()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "word1", "word2")
End If
End If
Next shp
Next sld
End Sub
ActiveX objects have a different set of properties/methods than regular PPT shapes. Assuming you have a reference to the AX textbox in a variable oSh,
osh.OLEFormat.Object.Text
will give you the text in the ActiveX textbox
I want to copy a text from a dialogue box in a webpage by using VBS. I have tried this
dim copiedTxt
'set copiedTxt = Browser("Finacle Universal Banking").Page("Finacle Universal Banking").Frame("HTMLDataFrm").WebEdit("_basic_docmsg_paraMsg").GetROProperty("value")
Use below statement only.
copiedTxt = Browser("Finacle Universal Banking").Page("Finacle Universal Banking").Frame("HTMLDataFrm").GetROProperty("value")
Please try by removing webedit. Try from the frame.
I am using the common dialog control to save a picturebox in my form as an image. However, when I test it out, the bmp file that is produced is blank.
I am using the line function to draw lines on the picutrebox. This is what I want to save.
My code:
Private Sub mnuFileSave_Click()
Dim FileName As String
savedlg.FileName = ""
savedlg.Filter = "Bitmap files (*.bmp)|*.bmp|"
savedlg.ShowSave
If savedlg.FileName = "" Then Exit Sub
picGraph.Picture = picGraph.Image
SavePicture picGraph.Picture, savedlg.FileName
End Sub
Any help as to why the saved bmp file is coming up blank would be appreciated, thanks.
Edit: I have also found that the picture box goes blank when the picture is saved as an image.
Answer is simple:
AutoRedraw on the picture box must be set to true. It was set to false before.
In 2003 the code worked perfectly, we just updated to 2010 and its affecting our outgoing proposals.
I've been looking on multiple sites and everything i have tried gives me all the pictures pasted into one grouped image OR gives me multiple boxes that say image cannot be viewed.
The pictures will always be located in column L, but it can be one picture or 50 and even none. So i need to be able to select all images, copy and open another workbook and paste in a designated column with the same format and as separate images, not as a single image which is what I am getting right now. Any help would be greatly appreciated. Below is the latest code I have tried, still getting a "single grouped image" when pasting.
Windows(ourName2).Activate
Sheets("Sheet5").Select
On Error Resume Next
ActiveSheet.Pictures.Copy
Windows("Proposal.xls").Activate
Sheets("Sheet2").Select
ActiveSheet.PasteSpecial Range("L7")
Update, attempting to use this code raises error on the line Set wbSource = Workbooks("ourName2")
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim shSource As Worksheet
Dim shDest As Worksheet
Dim shp As Shape
Set wbSource = Workbooks("ourName2") 'modify as needed
Set wbDest = Workbooks("MPlanner.xls") 'modify as needed
Set shSource = wbSource.Sheets("Sheet5") 'modify as needed
Set shDest = wbDest.Sheets("MAudit") 'modify as needed
shSource.Pictures.Copy shDest.Range("L7").Paste
This worked for me:
Sub test()
ActiveSheet.Pictures.Copy
With Workbooks("temp.xls").Sheets("Sheet1")
.Parent.Activate
.Activate
.Range("L7").Select
.Paste
End With
End Sub
Echoing Tim, this worked for me, resulting in non-grouped pictures. There should not be any reason you need to Activate the respective sheets.
The problem seems to be that you were using PasteSpecial method instead of Paste. I have a 2003 box at home I could verify on, but on 2010 Excel, the PasteSpecial method pasts the multiple pictures as a single object, whereas Paste puts them each individually.
Sub CopyAllPictures()
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim shSource As Worksheet
Dim shDest As Worksheet
Dim shp As Shape
Set wbSource = Workbooks("Book12") 'modify as needed
Set wbDest = Workbooks("Book13") 'modify as needed
Set shSource = wbSource.Sheets("Sheet1") 'modify as needed
Set shDest = wbDest.Sheets("Sheet1") 'modify as needed
shSource.Pictures.Copy
shDest.Range("L7").Paste
End Sub
I've found a few tutorials that explain how to use the windows API to get a custom icon in the system tray.
These are all for Visual Basic, and they don't seem to be scaling to VBA well.
I'm following this short tutorial:
http://atchoo.org/vb/systray.php
Basically, you have to set the hIcon value (a 'long' variable) but it does not work.
I've tried to use the LoadPicture() function, which does not give me any errors, but also fails to add a new icon.
I can't supply Me.Icon, nor can I set it on Form_Load.
Does anyone have any experience with this?
Using loadpicture was the right approach, but not directly.
I had to define a new variable first, and load that.
Like this:
Dim myPicture As IPictureDisp
strPath = "F:\Databank\Icons\stone.ico"
Set myPicture = LoadPicture(strPath)
And then, somewhere along the way, I could set hIcon without problems:
.hIcon = myPicture
When I change the trayicon (like, say, adding a balloontip) I have to supply the icon information again, too.