i'm using VBS to create a title screen and i have a problem trying to send a image behind te text.
Here is my code:
function page()
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set objDoc = oWord.Documents.Open("C:\xxx.docx")
objDoc.Sections.PageSetup.DifferentFirstPageHeaderFooter = true
Set head = objDoc.Shapes.AddPicture("C:\img.png")
head.PictureFormat.Brightness = 0.7
head.ZOrder msoSendBehindText 'I try to use msoSendToBack, SendBack, SendBehindText, Back and others and not work
end function
i just want send "head" to the back , the actual result is the image is not in the back of text, and the version of word is 2013.
If someone, know how to solve this, thanks in advance.
The solution was, the utilization of numeration
head.ZOrder 5
https://bettersolutions.com/vba/enumerations/msozordercmd.htm
with this change, i solve my problem.
Related
My problem is simple but I don't find the solution.
I know how modifiy dynamically a picture when I've the path.
But In my project I collect signature of people. I don't want file (not secure enough) then I store it in database (I use signature_pad and server side I use
Dim dataUri = MesDonnees.Img
Dim encodedImage = dataUri.Split(",")(1)
Bdd.field = Convert.FromBase64String(encodedImage)
...
But I don't solve how put it in footer of my document...
I read some works but always it's from details section and I just have string type, number, boolean... not byte or something
Thanks for your help
UPDATE
I've an idea. Try to link this image to ashx file
Dim IdAtt As Long = CLng(HelperParams.GetParamURL("IdAttach"))
Dim Typ As Integer = CInt(HelperParams.GetParamURL("Typ"))
Dim LesDatas As New MyEntities
Dim Att As Attachement = GetMonAttachement(IdAtt, LesDatas)
If Att IsNot Nothing Then
context.Response.ContentType = "image/png"
If Typ = 1 Then
context.Response.BinaryWrite(Att.SignCollaborateur)
Else
If Att.SignClient Is Nothing Then
Dim Vid() As Byte = New Byte(0) {}
context.Response.BinaryWrite(Vid)
Else
context.Response.BinaryWrite(Att.SignClient)
End If
End If
context.Response.Flush()
context.Response.End()
End If
Catch ex As Exception
End Try
If I put in IE: http://localhost:63888/Signature.ashx?IdAttach=4&Typ=2
I've my picture
But I try to create SignClient parameter et assign it location (x-2)
cryRpt.SetParameterValue("SignClient", "~/Signature.ashx?IdAttach=4&Typ=2")
cryRpt.SetParameterValue("SignClient", HttpContext.Current.Server.MapPath("/Signature.ashx") & "?IdAttach=4&Typ=2")
cryRpt.SetParameterValue("SignClient", "http://localhost:63888/Signature.ashx?IdAttach=4&Typ=2")
This 3 methods don't work.
I try to put directly : http://localhost:63888/Signature.ashx?IdAttach=4&Typ=2 in location (x-2) of image tabs : idem
I put a break point to ashx, never reach. Then I open network tab developpement tool and my ashx never call.
I've an picture in header (logo) and I change picture location with a path file (e:/../logo.png) and it's good.
Someone have an idea?
Finally, after try and try, the only solution I find is
1/ to make subreport (my request return only 1 line)
2/ in subreport delete all section except details section
3/ Create a class with property Contenu as byte()
4/ Add datafield in subreport to this new class and drop the field in detail section
For signaturepad, just put backgroundcolor : rgb(255,255,255) but penColor : (1,1,1)
else (CR or acrobat) show black image.
I've attempted the solution in the following.
Inserting an Online Picture to Excel with VBA
Unfortunately I get a run-time error '1004'
"Unable to get the Insert property of the Picture class"
which stops on the following code :
Set myPicture = ActiveSheet.Pictures.Insert(pic)
Could this be due to my Office version 2016 (64bit) ?
If not, are there any suggestions of how I might get embed images to adjacent cells in column AK using the image urls from column AJ ?
Thanks in advance
There's some evidence that Excel has trouble downloading from AWS, and I've recreated your issue using the URL you mentioned. In this case, if I were on a deadline I'd put in this fall-back method when the first one fails: download the file, then insert it into the document, then delete the file.
directDownloadFailed:
Dim FileNum As Long
Dim TempFile As String
Dim FileData() As Byte
Dim WHTTP As Object
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
WHTTP.Open "GET", imgURL, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
FileNum = FreeFile
TempFile = "path\to\save\img.jpg"
Open TempFile For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
Set img = ActiveSheet.Pictures.Insert(TempFile)
SetAttr TempFile, vbNormal
Kill TempFile
GoTo resumeProcessingImg
#keydemographic
I appreciate the response and that definitely sounds like an option but I cannot get that code to work or incorporate it into the code I'm using. I get a compile error "Label Not defined" on GoTo resumeProcessingImg
The following will download and embed the images into the cells but the code stops once it gets to the s3 aws image urls.
I'll try a few other ways to incorporate your code but I'm not having much luck with it so far.
This is my test file
Sub URL2IMG()
Dim pic As String 'path of pic
Dim myPicture As Picture 'embedded pic
Dim rng As Range 'range over which we will iterate
Dim cl As Range 'iterator
Set rng = Range("b2:b12") '<~~ as needed, Modify range to where the images are to be embedded.
For Each cl In rng
pic = cl.Offset(0, -1) '<~~ defines image link URL in column to the left of the embedded column
Set myPicture = ActiveSheet.Pictures.Insert(pic)
'you can play with the following to manipulate the size & position of the picture.
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
' currently this shrinks the picture to fit inside the cell.
.Width = cl.Width
.Height = cl.Height
.Top = Rows(cl.Row).Top
.Left = Columns(cl.Column).Left
End With
Next
End Sub
Background:
Entry is via a subform for adding/showing/linking images.
I do not want to store the image files within my DB, the image folder is separate. The DB will grow rather large in time.
I have created a click-control enabling a popup for user to browse and click on the imagePATH to be added in a Bound Textfield (called Bildadress, no not misspelled in My country, Grin ) in the subform.
See code below.
Then I add a new unbound Image-control and specify its Controlsource = the Textfield mentioned above.
For the firs image this works wonderful, but for the following the Image-control returns NULL (not show att all). The data in the Textfield updates as it should.
Will the 2nd stage only work in a 1:1 relationship OR can I (with your help) use VBA code to make this work?
OPTIMAL would be to get this to work and also a 2nd Bound Textfield just displaying the actual image file name. .
I hope someone out there have encountered this problem who also didnt want to use Attachment to store the files within the databae.
CODE:
Private Sub AddFilePath_Click()
Call Selectfile
End Sub
Public Function Selectfile() As String
Dim Fd As FileDialog
Set Fd = Application.FileDialog(msoFileDialogOpen)
With Fd
.AllowMultiSelect = False
.Title = "Välj önskad fil"
If .Show = True Then
Selectfile = .SelectedItems(1)
Me.Bildadress = Selectfile
Else
Exit Function
End If
End With
Set Fd = Nothing
End Function
If you use a bound textbox that holds the image-path then you can use
Me.Imagecontrol.Picture = Me.BoundTextControl.Value
to load the picture into an unbound image control. In your case that would be something like
If .Show = True Then
Me.Bildadress.value = .SelectedItems(1)
Me.Bild.Picture = Me.Bildadress.value
Else
It would be best to also load the respective picture in the OnCurrent Event.
Private Sub Form_Current()
Me.Bild.Picture = Me.Bildadress.value
End Sub
However, keep in mind that access is a one-file-database and you break that paradigm when using links to external files where the files would belong into the DB.
I have a workbook full of text and image hyperlinks, I've got some code that will deal with the text URLs nicely, however, the image links are presenting a problem as they don't sit in the flow of the page to be able to pull those links. I don't know how VBA treats these as objects, is it possible to target or cycle through them to pull out their URLs?
Try this way (I used your code and put some error handling instructions):
Sub test()
Dim WriteRow As Integer
WriteRow = 1
Dim imglink As Shape
'error handling
On Error Resume Next
For Each imglink In Sheets(1).Shapes
'if any shape doesn't have hyperling we would skip it
ActiveWorkbook.Sheets(3).Cells(WriteRow, 1).Value = imglink.Hyperlink.Address
If Err.Number = 0 Then
WriteRow = WriteRow + 1
Else
Err.Clear
End If
Next
End Sub
I expect that you have an error each time you check Hyperlink for shape which doesn't have one.
I have written some code in vbscript to automatically send mails to a recepient using outlook,Everything is working fine but i am having just one issue, The format what i have selected for the message body getting changed in the recepient's mail box.I used font color- blue and font face -calibri but it got changed into Times new roman without any color.
Any solution?
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0) 'olMailItem
With MyItem
.To = "abc#com"
.Subject = ""
.ReadReceiptRequested = False
.HTMLBody = "<font size='3' face='Calibri' color='#151B54'>Hi,Whatever written here got changed into plain text.<font>"
.Attachments.Add "C:\Excels\"& objFso.GetFileName(objFile.path)
End With
MyItem.Display
End if
Or is there any setting that i have to change in the outlook for the sent mails?
This works perfectly fine with me:
MailItem sendMail = Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);
sendMail.Subject = "test";
sendMail.To = SenderName; //or email
sendMail.HTMLBody = "<font size='50' face='Verdana' color='#ff0000'>Hi,Whatever written here got changed into plain text.<font>";
sendMail.Send();
When I send this to myself I recieve a big red text in verdana
Note that this is c# so I'm not sure if it will help you
EDIT:
One more thing: font size='3' won't work with me either. Because it's too small to display decently