[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Visual Basic Classic





Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

Share tech news, updates, or what's on your mind.

Sign up to Post

I would like to get some information from outlook. Basically, get the number of emails received every month, but not just for the current view (this is what my code does right now, fut for all subfolders, up to 2 depth). I have tried with this:

'The following codes are working to count by day
Sub CountReceivedEmailsbyDay()
    Dim objItems As Outlook.Items
    Dim objItem As Object
    Dim objMail As Outlook.MailItem
    Dim strMonth As String
    Dim dReceivedTime As Date
    Dim strReceivedDate As String
    Dim i, n As Long
    Dim strMsg As String
    Dim nPrompt As Integer
    Set objItems = Outlook.Application.ActiveExplorer.CurrentFolder.Items
    objItems.SetColumns ("ReceivedTime")
    strMonth = InputBox(“Enter the specific month.(Format: yyyy-mm)”, “Specify Month”)
    If strMonth <> "" Then
       n = 0
       For i = 1 To objItems.Count
           If objItems.Item(i).Class = olMail Then
              Set objMail = objItems.Item(i)
              dReceivedTime = objMail.ReceivedTime
              strReceivedDate = Year(dReceivedTime) & “-” & Month(dReceivedTime)
              If strReceivedDate = strMonth Then
                 n = n + 1
              End If
           End If
       Next i
       strMsg = "You have received " & n & " emails on " & strMonth & "."
       nPrompt = MsgBox(strMsg, vbExclamation, "Count Received Emails")
       nPrompt = MsgBox("Please input the specific month!", vbExclamation)
Angular Fundamentals
LVL 12
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Hi Experts,
we have a site created in Caspio that has some required fields.
We realized that some of the required fields are coming thru w/o containing data.
So were told by Caspio that is probably due to those users using an old browser.
They created a field named user_agent that will capture which browser were used for each record data entry.
Now I created a list of all records with missing data in required field along with the data captured in this field named user_agent (browser).
See attached.
Wondering what are those values are and how can we sent a message informing this and this browser is not supported...
Hi Experts,

I have attached a VB Utility being regularly used by me. It is used to prepare some returns, where we input the data and the output is produced in the shape of some encrypted file format for onward submission. But it can also be used to prepare a correction return also. In that case we need to import a Consolidated file and then the return can be amended or extended.

What I presently do
--Download all the conso files

--Import the files one by one in above software.
>>Here we need to Select Form No (24Q / 26Q / 27Q / 27EQ).
>>Type of statement to be prepared is always "Correction".
>>Option to be selected "Import Consolidated File"

--Copy the data from the tabs and paste them in different sheets of Excel (Normally there are 3 Tabs, but data from 1st Tab is never copy pasted. There may be 4 tabs for the 24Q - 4th Quarter of a Financial year in which case the last 3 tabs are copy pasted)

Name of Tabs (from which data to be copied and pasted in Excel) in case of each Form
24Q >  Challan , Annexure I        (in case of 4th Quarter of FY tabs to be Copy pasted are Challan, Annexure I and Annexure II
26Q >  Challan , Annexure I
27Q >  Challan , Annexure I
2EEQ >Challan , Annexure I

Challan Data can be pasted in the same Excel Sheet for All Form Types, whereas for Annexure I and Annexure II, we need separate sheets for Each Form.

I wish some script (or anything like that even if that is in Excel) which can
I have a VB script that I want to adapt to remove a desktop link from the currently logged on user's Desktop.  It isn't working and I get no error messages - no nothing.

On Error Resume Next
Dim FSO, WSHShell, Regkey, Username, strFolder, UserPath, objShell

Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\"
Username = WSHShell.RegRead(RegKey & "LastLoggedOnSAMUser")
Username = Mid(Username,7) 

Set FSO = CreateObject("Scripting.FileSystemObject")
UserPath = "C:\Users\" & Username 
strFile = "C:\Users\" & Username & "\Desktop\CMS Supervisor*.lnk}" 
if FSO.FileExists(strFile) = True then  FSO.DeleteFile DesktopPath & "\CMS Supervisor*.lnk"

Open in new window


I am running into quite an unusual problem and was wondering if anyone has experienced this issue before. I have an ActiveX Control that I have made that uses a Picture Box and displays an image from Azure blob storage by converting that image's memory stream into an image. I use this ActiveX Control for a Microsoft Access 2002 application. This ActiveX Control works great on forms, but on reports it doesn't display fully (Please see attached images). Anyone know why?
In my application, i have a common dialog component, on click of this component a dialog box will open where i can select a file and open it to get the list of account names that are there in the file.

The component was working fine, but from few days, when i click on this component my application is getting closed.

can somebody help me on this!!!!

Note: I have component added in my project. and the file is also present.
I had this question after viewing Failed to activate control vb.UserControl.
I have a similar problem and I know it is caused by two seemingly incompatible programs.
If I reinstall the app which reported the problem, the other one stops working and vice versa.
How can I get both apps to work in peace ?
How to create push message app for LAN in winform app like asp.net-SignalR
i want to write the code in vb6 (Visual Basic6) language to send sms through web api (after creating account in smsgateway.me site and mobile app in my android phone set) using json method (and how to get token) in vb6. Actuallay i know how to send sms using http url but unable to send sms through json). can you help in this case? thanks
When exporting text to a .tab file, then opening a Word doc, then trying to insert a portion of the tab file into this Word doc, I get an error message - "Run-time error '4605':  This method or property is not available because this command is not available for reading."  When I click on Debug, it then highlights the Selection.InsertFile lines.  I've never received this error before; however, I have a new PC, Windows 10, 32-bit OpSys (to allow DOS), and MS Office Professional Plus 2013.  I checked and the .tab file does exist.  Any suggestions?

    ChangeFileOpenDirectory "R:\fmExports\MastersandMacros"
    Documents.Open FileName:="woodrich_letterhead.doc", ConfirmConversions:= _
        False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
    ChangeFileOpenDirectory "R:\fmExports"
    Selection.InsertFile FileName:="woodrich4word.tab", Range:="", _
        ConfirmConversions:=False, Link:=False, Attachment:=False
Build an E-Commerce Site with Angular 5
LVL 12
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

In Example1.xlsx, Column "I" has words in each cell like Entire, Shared, SE.1/4, etc.  For every cell in Column "I" that has the word ENTIRE, I would like to add 7 rows below the initial row, copy everything from the initial row into the seven added rows and then renumber column "G"(Space?) from 1 through 8. (See Example2.xlsx).  How would I do this in Excel 2013?
Hi Experts,
Wondering if there is a way to link an Access 2003 application to an Excel XLSX file?
if not, can someone post code to convert file from XLSX to XLS?
ciao a tutti, volevo sapere in che modo era possibile esportare dei dati da una tabella di un db su sql server in excel tramite framework .net su vb.net
Fino ad oggi uso questa procedura ma per tabelle con molti dati il procedimento impiega troppo tempo. Importo la tabella su un datatable o un datagridview per visualizzarla al front end, una volta caricata con una funzione che si basa sulla classe interop excel vado a ciclare tutte le righe della tabella e le scrivevo su un file excel.
Mi sono accorto che per tabelle molto grandi l'export dura troppo tempo, allora spesso ricorro all'importazione direttamente da excel sulla scheda dati/nuova query/da database/da database sql server. la scheda mi richiede il server, il database e la query e con pochissimo tempo con il net framework si caricano tabelle con molti dati, già convertite anche per ogni formato cella. La mia domanda è se la stessa procedura può essere richiamata da vb.net, quindi con una funzione che una volta passati i parametri di server,db,query scriva velocemente su un file excel (.xlsx)
How to edit 2 cell fields in multiple excel files in a folder/subfolders automatically using VBA based on starting name of file

For example I have a root folder of c:\master templates
Under that folder I have subfolders with clients names as the folders
Under each client folder I have folders with job numbers
Under those job number folders are the excel files that I want to change
They all start with the name of set_up sheet *
There could be 2 set_up sheet excel files or 3 or 5, it all varies based on client and job, but they are all named the same starting with "set_up sheet*"
I want to change 2 cells in each of these set_up sheet*.xls files for every directory/subdirectory that contains those files
Basically replace 2 fields
M14 with "Stick Out"
S14 with "Vending #"
Then I want to save each excel file back and close and then loop through and do the same thing for all the other excel files named the same thing in each directory/sub

Here is the code I have so far which I know isn't correct. It's just what I wrote by watching a youtube video on it. I know I am on the right track I just need some help

Sub LoopThroughDirectorytoedit()
Dim MyFile As String
Dim Filepath As String
Dim q As Long

Filepath = "C:\mastertemplates\"

MyFile = Dir(Filepath)

Do While Len(MyFile) > 0
If MyFile = "bookz.xlsm" Then
Exit Sub
End If

Workbooks.Open (Filepath & MyFile)
For q = 1 To Application.Worksheets.Count
Range("M14") = "Stick …
project to pragmatically click email "confirm" must be in VB6

the program must:

scan inbox
open email if keyword in subject line example  "Bitrex"
find button with keyword in it example  "confirm" and select it
capture the result screen and save in folder  

Im not sure where or how here on Experts i can post this , or even if I can , any help appreciated.
VB logon script that will set IE so when you open a new tab the user's frequent sites will show up, not MSN's top sites.

We have a simple application that was done by a predecessor. All it does is allows users to enter 'item numbers' and send to print. The item data is saved on a separate excel sheet in the same folder. All dll files, EXE. file and excel file are in the same folder. I've just copied this folder to a new machine trying to replicate the process. I can run the application but when I click send to print button on the application I get below error;

"Unhandled exception has occurred in your application if you click continue the application will..."

"could not load file or assembly microsoft.reportviewer.common version="

I've tried installing the relevant files for above exceptions. However, think this is to do more with the 'Print' button on the application and coding behind it.
Please see attached.

Can someone advise what I need to do to get this to work please?

Thanks in advance.
Wondering why the code below won't set as the selected item (a number 1-5) based on the database field value?

Thanks in advance for any help!

    sThisRdr = lstRdrPriority.Text
    Set rs = New ADODB.Recordset
    sql = "SELECT ReadOrder FROM FinishReader WHERE MeetsID = " & lMeetID & " AND ReaderNum = " & sThisRdr
    rs.Open sql, conn, 1, 2
    lstPriority.Text = rs(0).Value
    Set rs = Nothing

Open in new window

This code only captures the first part of the page, I think because the whole page doesn't load until you scroll to the bottom of the page, which I don't know how to do programatically.

Set http = New WinHttpRequest

x = "https://www.flickr.com/photos/conationalguard/page1"

http.Open "GET", x, "False"
myval = http.ResponseText

Open in new window

Determine the Perfect Price for Your IT Services
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

MSComm1.Output = "AT\n" & vbCrLf <br/>
Sleep 100<br/>
MSComm1.Output = "AT+CSCS=UCS2\n" & vbCrLf<br/>
Sleep 300<br/>
MSComm1.Output = "AT+CMGF=1\n" & vbCrLf<br/>
Sleep 400<br/>
MSComm1.Output = "AT+CSMP=17,168,0,8" & vbCrLf<br/>
Sleep 500<br/>
MSComm1.Output = "AT+CMGS=" & Chr(34) & Text1.Text & Chr(34) & vbCrLf<br/>
Sleep 600<br/>
MSComm1.Output = Trim(txtMsg) & " " & Chr(26)<br/>
MsgBox "MESSAGE SENT"<br/>
On Error GoTo p
MSComm1.Output = "AT\n" & vbCrLf
Sleep 100
MSComm1.Output = "AT+CSCS=UCS2\n" & vbCrLf
Sleep 300
MSComm1.Output = "AT+CMGF=1\n" & vbCrLf
Sleep 400
MSComm1.Output = "AT+CSMP=17,168,0,8" & vbCrLf
Sleep 500
MSComm1.Output = "AT+CMGS=" & Chr(34) & Text1.Text & Chr(34) & vbCrLf
Sleep 600
MSComm1.Output = Trim(txtMsg) & " " & Chr(26)
Sleep 700
setStatus "Done..."
Exit Sub
    MsgBox "Some Error Occured..." & Err.Description
End Sub

in the above example of visual basic 6.0 i have sending sms with gsm modem in AT commands but when I need to send sms in unicode this code gives receiver mobile a ???? format sms what is the solution
I had this question after viewing Locating ClientCertificate to use in WinHTTP.

Similar question, when using the SetClientCertificate property on a WinHttpRequest, I receive a "Certifcate is required to complete client authentication". The certificate has been created successfully, and appears in the Certifcate Store under Console Root -> Certificates (Local Machine) -> Personal -> Certificates.

The Issued to is ABC Certificate, the Friendly name is ABC

The parameters I am using are as follows:

myMSXML.SetClientCertificate "LOCAL_MACHINE\\Personal\\ABC"

I've tried ABC Certificate etc... tried putting the certificate in different stores, tried a number of other things, but still getting same message returned.

How did you go with your problem referencing a certificate in the Cert Store?

This is a follow-up to another thread located here:

Create an executable file to open a non-executable file

In that thread, expert Joe Winograd provided a solution which involves creating an AutoHotkey (ahk) "Run" command (which I know how to do) then compiling the resulting .ahk file to create an .exe file. That was a great solution and I'm glad to now know how to do that. However, since closing the previous thread, I've realized that that solution is not practical for the specific purpose* that prompted my question.

As a result, I'm back to my original question which is:

How do you directly create an executable file (.exe or .cmd) to open a non-executable file (.xlsm, .txt, .ahk, etc)?

In the previous thread, expert tuvi suggested putting the following in a .cmd file:

start C:\Users\UserName\FolderName\FileName.xlsm

Open in new window

Unfortunately, while I know how to place a command in the cmd/prompt/DOS window (not sure what it's called), I do not know how to create a .cmd or .exe file. I tried simply pasting the above line in a Notepad window then saving it, first with a .cmd extension and then with an .exe extension but neither of those worked.

It seems like something I should know how to do but that's why I'm happy all of you great experts are available to answer questions. :)

Trying to get a session code response from the Betfair site using VB6. My software, which I've written and been using in a particular industry for 20 years, therefore huge amount of code, so trying to do it through VB6, and I've done other XML feeds using the Web Service, which are working really well.

So.... the issue is, i make a call to the site, and the return I get is HTTP ERROR CODE 400 through the response text.

Part of the process, required I create a certificate, using OPENSSL , which worked fine, and the certificate uploaded to my test account on Betfair, and the account has been enabled for access. I've also sent the P12 Key to my certificate store on my local Windows 7 (32 Bit) development computer, which allowed the call to go through without any "Certificate Required" prompts, so appears to get through that part. However, once through the response coming back is "HTTP ERROR CODE 400", in the response text. So it's not making my code fall over in any way, just not returning a session key, which is obviously required to proceed further.

The code is as follows, of which a username and password string is passed to the function from a login form.

Public Function GetBetfairSessionID(sUserName As String, sPassword As String) As BetfairSessionInfo
    Dim AuthURL As String

    AuthURL = "https://identitysso.betfair.com/api/certlogin"
    Set myMSXML = CreateObject("MSXML2.ServerXMLHTTP")

Open in new window

Sub Link()

Dim Turbidity As Long
Dim RawTurbidity As Range

'Sets variables Turbidity being the ActiveCell and RawTurbidity refering to the last captured cell in raw sheets'
Turbidity = ActiveCell.Row
Set RawTurbidity = Sheets("Raw Data").Range("C4").End(xlDown)

'The formula assiging the last captured cell in Raw sheets to the active cell'
Sheet1.Cells(Turbidity, 4).Value = RawTurbidity.Value
End Sub

Open in new window

This is my code and it does pretty much what I want it to do. I have an instrument that spits data into column C in Raw Data sheet. What this macro does is copy that data into column D in Sheet1. I have another small Macro running on Raw Data that calls this macro whenever a change is made in column C in RawData and that's what activates this macro. Anyway what I'm trying to do is after the calculations have been copied to have the activecell automatically go to the next row just like pressing enter when your in a cell. Typically ActiveCell.Offset(1,0).Select would be the line for that. For some reason when I add that to the end of the macro it copies the data into the next four rows.

In case you were wondering the analyst don't do the analysis on sheet1 in order hence why I had to have Raw Turbidity copied into the activecell instead of just doing the available blank line.

Visual Basic Classic





Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.