Inserting Gif in VB6 Program - vb6

I have created a new VB6 program and i would like to put a gif in so it can play on the loading screen. I have searched online on how to do it and it shows you have to use a web browser and picture box to view it. i know how to insert the web browser and picture box. I do not know how to code it with the gif.

You can do this multiple ways, but the simplest way is to use a picture box and web browser. The code to use is this:
Private Sub Form_Load()
Dim loc As String
loc = App.Path & "where the gif is located\somegif.gif"
Animation.Navigate "about:" & "<html>" & "<body leftMargin=0 topMargin=0 marginheight=0 marginwidth=0 scroll=no>" _
& "<img src=""" & loc & """></img></body></html>"
End Sub

Related

how to use SendKeys method in vb script to select everything on page?

I am trying to run a vbscript that will load up a html page in chrome and then do control+a which will select everything on the page, with the ultimate view to copy it and then paste it into excel.
this my script so far:
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim iURL
Dim objShell
iURL = "C:\Users\Aasfasf\AppData\Local\Temp\TD_80\hpqc\52136023e30\****\121200.html"
set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)
WScript.Sleep 1500
WshShell.SendKeys "^a"
when I run it loads up the html page, but i dont think the control+a command is working as nothing is selected.
Two suggestions:
The focus is probably not on the content in chrome. Try sending a Tab key press a couple of times first to see if that fixes it.
A better approach to this might be to just read the contents of the file, then delete all the markup from the document using regex.
Excel can just load your web page without needing any help from you.
Alt + D, D, W

Automate 5 Firefox Tab

I am looking to automate our reporting. We currently have 5 Tabs in Firefox that we refer to for reporting. Each Tab has a unique url that changes each morning. We then have to each morning update these URLs (from an excel speadsheet). I would like to automate this. I do have a few constraints on this though. I cannot open a new tab for each new url (so basically it needs to be a url replace in each tab). I have looked into selenium but cannot get it to work
http://www.makeuseof.com/tag/using-vba-to-automate-internet-explorer-sessions-from-an-excel-spreadsheet/
and
http://www.makeuseof.com/tag/how-to-automate-firefox-or-chrome-with-vba-and-selenium/
So I was wondering if it could be done another way either using pure VBA or a batch file?
You need to add a reference to Microsoft Internet Controls and Microsoft Shell Controls and Automation. See screenshot below.
Code:
Sub Work_With_Open_IE_Instance()
Dim objShell As Shell
Dim objIE As InternetExplorer
Dim objWin As Object
Set objShell = New Shell
For Each objWin In objShell.Windows
If TypeName(objWin.Document) = "HTMLDocument" Then
Set objIE = objWin
'~~> This will display the URL of the IE which we will use to bind
Debug.Print objIE.LocationURL
'~~> Example to bind
'~~> Change URL to your existing URL
Select Case objIE.LocationURL
Case "https://www.google.com"
With objIE
.Refresh
'
'~~> Rest of the code
'
End With
Case "http://in.msn.com"
With objIE
.Refresh
'
'~~> Rest of the code
'
End With
End Select
End If
End If
Next objWin
End Sub
The Select Case is just for demonstration purpose. If you want to work with them one after the other then don't use Select Case. Use If/EndIf one after the other.

External Images Referencing in ACCDB

I have a database application making use of VBA code that has reached its 2GB size limitation with image attachments on a per-record basis. We're wanting to have all forms in the application move away from "uploading" images as attachments for records, and instead upload them to a directory on a network server and reference the image files in the forms.
At this point, I'm trying to figure out the best way to approach this. Is it feasible to have the user somehow pull up an "Upload" dialog through an Access form? I've tried a couple cobbled-together solutions for Open File dialogs in VBA, but they've never quite worked properly.
Summary: File type is ".ACCDB", I need to allow users to upload images in a New Record creation form, have the images stored in a Network directory, and accessed on-the-fly throughout the application.
Thanks in advance.
From a general database point of view, you should not store images directly in a database, unless they are very small (less than 1 MB approximately), and you actually have the space to store them. The most common practice is to store the image path in the database, and then load those images directly from your the file directory where the images are stored when needed. It will add another level of complexity, but will reduce your DBs size radically.
Update:
This code allows the user to click some element frame in the form, store the path in the DB (with path as the username.jpg), and display the picture to the user afterwards in the clicked frame:
Private Sub SignatureFrame_Click()
On Error GoTo ErrorHandler
' Get path for the new picture from a dialog box
Dim Path As String
Dim fd As FileDialog
Dim ffs As FileDialogFilters
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
Set ffs = .Filters
With ffs
.Clear
.Add "Pictures", "*.jpg"
End With
.AllowMultiSelect = False
If .Show = False Then Exit Sub
Path = .SelectedItems(1)
End With
' Update the picture in the user interface
Me![SignatureFrame_Click].Picture = Path
' Copy the signature into the local Signature folder of the DB
Dim fs As Object
Dim oldPath As String, newPath As String, file As String
oldPath = Path 'Full path the file is located in
newPath = CurrentProject.Path & "\Signatures\Users\" & Screen.ActiveForm.UserName & ".jpg" 'Folder and path to copy file to
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile oldPath, newPath 'This file was an .jpg file
Set fs = Nothing
' Set the new picture path for the form
Screen.ActiveForm.SignaturePath = newPath
Exit Sub
ErrorHandler:
MsgBox "Could not upload the image. Please check that the file format is of type jpg."
Resume Next
End Sub
Then at some later point in some other form you can retrieve the image like this:
Me!SignatureFrame.Picture = CurrentProject.Path & "\Signatures\username.jpg"
PS: The code has been translated in the SO editor, so I cannot guarantee that there are no mistakes.
Hope that helps!

Drag and drop a shortcut on to HTA

I'm trying to build a local HTA (HTML Application) that will send me to a website I designate. I've got most of it working, as in it currently allows me to type in an address and choose whether to open that URL in either Internet Explorer or Firefox (both in normal and in private).
What I'm asking is if there is a vbscript I can add onto my HTA that will allow me to drag and drop a shortcut that is on my desktop and click a button to do the same as typing it out. Essentially, I would love for it to be similar to Google Image search. Like you can either type in or drag and drop an image to search. This is just for me to quickly open webpages that I have a shortcut saved. I know i could use the favorites option, but I often use many different computers and I have a flash drive that has all my stuff on it.
You want to drag file (url shortcut in this case) and drop it inside open .hta window? If so then looks like what you are looking for is not yet implemented in HTML Application.
Edit
If you have recent Internet Explorer version (9+) then you can play with the HTML5 native
drag and drop feature. As I'm on XP where IE8 is the most upper version, I can't help
in that challenge.
If that so difficult or not applicable then may consider plan B, where can make a function
on start up that scan your Desktop for *.URL files and populate them in Select element, so you'll end with something like:
<select id="urlList">
<option value="" selected>---</option>
<option value="http://...">Shortcut1.url</option>
<option value="http://...">Shortcut2.url</option>
</select>
<input id="urlAddress" type="text">
...and can control it with OnChange event by including a handler into your Head section:
Sub urlList_OnChange()
Document.All.urlAddress.Value = _
Me.Options(Me.selectedIndex).Value
End Sub
Here is a quick snippet to get started.
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strDesktop)
For Each f In fld.Files
If f.Type = "Internet Shortcut" Then
MsgBox f.Path & vbNewLine & ReadURL(f.Path)
End If
Next
Function ReadURL(urlFile)
With CreateObject("Scripting.FileSystemObject")
With .OpenTextFile(urlFile, 1)
.SkipLine
ReadURL = (Split(.ReadLine, "="))(1)
End With
End With
End Function
Yes, you can, see this article from Hey, Scripting Guy (the best resource for Vbscript and Powershell stuff). Dragging something onto a shortcut is almost the same as passing parameters to a script (HTA here).
http://blogs.technet.com/b/heyscriptingguy/archive/2005/04/20/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts.aspx

What causes Outlook 2007 to prompt "A program is trying to send an e-mail message on your behalf?"

I have a custom form built within Outlook that sends an email notification any time a change is made. Because of the specifications of the form, I had to add a bit of VBScript (unfortunately) to the form that does the emailing on the closing event of the form.
The form is currently published and works well. The only problem that appears to be cropping up is that I am the only one of the users that use the form that gets prompted with the following dialog:
Nobody else that uses the form is getting the dialog. This dialog box forces you to wait until the progress bar is complted before it "Allow"s you to send the email (about 5 seconds). Is it because I am the publisher? Or is it a client side setting that I am running into? How do I disable this puppy?
In case its relevant heres the source:
Sub SendAttach()
'Open mail, adress, attach report
Dim objOutlk 'Outlook
Dim objMail 'Email item
Dim strMsg
Const olMailItem = 0
'Create a new message
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = Item.UserProperties("Assigned To")
objMail.cc = Item.UserProperties("Bcc")
'Set up Subject Line
objMail.subject = "Work Order Notifications: " & Item.UserProperties("Work Order Number") & " - " & _
Item.UserProperties("Subject") & " Due " & Item.UserProperties("Due Date")
'Add the body
strMsg = Item.UserProperties("Specifications") & vbcrlf
strMsg = strMsg & Item.UserProperties("Constraints")
objMail.body = strMsg
objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
objMail.Send
'Clean up
set objMail = nothing
set objOutlk = nothing
End sub
Security here is not a concern. If somebody has managed to start sending emails from my workstation, I have much bigger problems than email spoofing!
As side note, I couldn't decide if SO or SU was the best place for this question. Please redirect accordingly if necessary.
I ran into this problem a while back whilst trying to accomplish somehting slightly different, but for this purpose is the same. The link HK has provided makes for good reading and helps to understand what's going on, however in the end I chose not to go with any of the options discussed on the page. Instead I kept it simple and decided to fool outlook into thinking I was sending the e-mail rather than an automated process, I did this by replacing the objMail.Send with a SendKeys alternate to mimic myself pressing the send button, bit ugly but worked in my case.
Edit:
You can use this sendkeys statement:
SendKeys "%{s}", 1
This basically calls Alt + S which triggers the outlook send button.
Three options
- Use a pc without the MS Outlook security patch
- Use the redemption ocx (google it up to download)
- Use SMTP instead of outlook
For the second option here an example
Function sendmail2 (sRecipient, sSubject, sMsg, sAttach)
on error resume next
dim SafeItem, oItem
set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
set oItem = oApp.CreateItem(0) 'Create a new message
With SafeItem
.Item = oItem 'set Item property
.Recipients.Add sRecipient
.Recipients.ResolveAll
.Subject = sSubject
.HTMLBody = sMsg
.Send
End With
End Function
I ran into the same problem and because my application runs on Windows 7 I was able to use Windows Mail Client (wlmail.exe) to send emails instead of MS Outlook. With Wlmail, the warning still comes in the default behavior but there is an option to turn off the warning by going to Options > Security tab and once you turn it off the program can send mails without bringing up a pop up.
Another possible workaround is to update the registry setting on your machine.
https://support.microsoft.com/en-gb/help/3189806/a-program-is-trying-to-send-an-e-mail-message-on-your-behalf-warning-i
This link outlines how to identify the relevant registry key and what value should be set. This allows you to override Trust Center settings.

Resources