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.
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 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
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 have lot of pictures embedded in the Microsoft Powerpoint 2013 presentation. In Powerpoint 2013, I can right click on a picture object and then use "Save As Picture" to save the image to local disk. But this is manual way. I want to know if there is any way of automating the same through VBA? I am able to loop through the Shapes collection and then determine the type of the object. But I am not able to figure out which properties or methods are relevant for storing the picture to the local disk? Following is code snippet of iterating through the Shapes collection and determining if the Shape is of type msoPicture
For currentSlideIndex = 1 To totalSlidesCount
Set currentSlide = ActivePresentation.Slides(currentSlideIndex)
For Each mediaShape In currentSlide.Shapes
mediaCounter = mediaCounter + 1 'for each shape in the slide
If currentSlideIndex = 3 Then
If mediaShape.Type = msoPicture Then
MsgBox ("Shape Type Picture is " + CStr(mediaShape.Type) )
End If
End If
Next mediaShape
mediaCounter = 0 'Reset to 0 for the new slide
Next
You can export the current shape to a picture using the shape's .Export method.
This is normally hidden, so you won't get intellisense help on it by default, so:
Go into the IDE
Press F2 to open the object browser
Rightclick in the pane to the right of Classes, where you see "Members of ..." at the top.
Put a check next to Show Hidden Members
Now you'll get intellisense guidance when you type .Export on a slide shape.
Note also that if a shape is Type 14 (placeholder), it can contain a picture, so you may want to add something like:
If mediaShape.Type = msoPlaceholder Then
If mediaShape.PlaceholderFormat.ContainedType = msoPicture Then
' it's also a picture
End If
End if
And to add further entertainment value you might also have .Type = msoLinkedPicture, and even in some cases msoEmbeddedOLEObject that happens to be a picture.
I am trying to update an old VB6 application. I am struggling with changing the backcolor of the SSTab control at runtime.
I know that I cannot just set the Backcolor to the required colour.
At designtime I have created a label on each tab and then resized the label to the sstab dimensions. Then I set the label backcolor. This works fine.
However, what I really want to do is to do this at runtime so that if a new tab control is added on a form in the future I dont need to manually do this at designtime each time.
I would be grateful if someone can point me in the right direction to create and display a label on every tab of a SSTab control at runtime?
I dont have frames on all the tabs so I dont want to use the frame container to hold the label. I would rather just have the label placed on the tab container at runtime.
Thanks and I look forward to your replies.
As svinto says, you can load new controls to a Control Array, but there's a bit more to it than that.
Firstly the new controls are not Visible, so you must set .Visible=True
You also need to set the current tab before creating the control to get it sited on that tab.
Assuming you already have the first label on the first tab:
For i = 1 To Me.SSTab1.Tabs - 1
Me.SSTab1.Tab = i
Load lblOne(i)
lblOne(i).Visible = True
Next
Also, this doesn't work in the Form_Load event, but does in Form_Activate
There is another method to create the Labels from scratch rather than using a Control Array, which might be better as you don't need to add the first Label to the form:
Private Sub Form_Activate()
Dim lbl() As Label
Dim i As Integer
Dim name As String
ReDim lbl(SSTab1.Tabs - 1)
For i = 0 To Me.SSTab1.Tabs - 1
Me.SSTab1.Tab = i
name = "MyLabel" & CStr(i)
Set lbl(i) = Form1.Controls.Add("VB.Label", name)
Set lbl(i).Container = Me.SSTab1
lbl(i).Visible = True
lbl(i).Caption = name
lbl(i).Move 40, 345
lbl(i).BackColor = vbGreen
Next
End Sub
Create one label at design-time, and set it's index to 0. You can later on do Load labelname(newindex) to create more instances of the label. Position them once created, set the background color and you're all done.