[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 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
Exploring ASP.NET Core: Fundamentals
LVL 12
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

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
I'm using VB6
I have a Class Questions which includes a dictionary dicAnswers.

I create an Object (oQst)  for each loaded question record (from SQL).
I stuff the object into a dictionary dicQuestions.
There is a subset of all the question records called PAQuestions.
I create an object (oPAQst) for each member record of the subset.
I use a separate load statement for get the SQL data for this subset record (I don't use: Fill oQst. If subset then oPAQst = oQst).
I stuff oPAQst into a different dictionary dicPAQuestions.

Is it save to assume that the objects in dicQuestions are different from the objects in dicPAQuestions?
If i change a value in one of dicQuestions objects that the related object in dicPAQuestions isn't changed?
if a value in dicQuestions.item(x).Answers.item(y).pos = 5
that I can have dicPAQuestions.item(x).Answers.item(y)=25
and the two are treated as separate items.
I need help with VBA code that will check a String to see if it contains some substrings, using logical operators. If it the does contain the stubstrings then it should display a message Box that should confirm that the string does contain the sub strings I am looking for.
Please look at the code to see what I would like to do.
Dim myString As String

myString = “I like mangoes and oranges.”
      If InStr(myString, "mangoes") And InStr(myString, "oranges")  > 0 Then 
           MsgBox  “The string does contain the words mangoes and oranges”
       MsgBox “The string does not contain the words you are looking for”

End if

Open in new window

In the code I have written, I am expecting that because myString does contain both the words “mangoes” and “oranges” in it my condition will return true and I will see the message “The string does contain the words mangoes and oranges”. However, this code is not working. I would appreciate help in how I should write this code to get the desired result.
Please note that I would like the condition to return true only if myString contains both the word “mangoes’ and “oranges” in it.
Thank you for your help.
Hello experts, I have the following procedure which allows me to refresh the various pivot tables I would like to add some enhancements:

Sub Refresh_Pivot()
Dim PT As pivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
Next PT
Next WS
End Sub

Open in new window

1.      Run the procedure after I change a data or after a save
2.      Include in the procedure the refresh of the various tables in the workbook

Thank you very much for your help.
In Access db when a user clicks the Mail Report button on a form an email is created and populated with the information to send to a Distribution List. I would like the user to be presented with a list of email addresses to be able to select from, how do I do that. VB newbie.  Below is my code for sending the form.

strDocName = "PReport"
    strFilter = "DQR ='" & Me!DQR & "'"
    DoCmd.OpenReport strDocName, acViewPreview, , strFilter
    DoCmd.SendObject acSendReport, "PReport", "PDF Format", "New-HIX-DQR@company.com;", "", , "New DQR", "Please see the latest DQR issued by HIA QA", , False
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?
I am using VB6 and when I run the following code, I get a "Text property is read only" error.  I know the output of the recordset contains a blank value and a blank value is located in the Combo6.  Why would it produce an error when executing Combo6 = rec!SubGroup if the value is basically there?

If Not IsNull(rec!SubGroup) Then
                    Combo6 = rec!SubGroup
                    End If

Open in new window


I have made a function to synchronize some tables between two or more databases in my app. But I needed a more efficient way of doing it, faster especially.
I would prefer a .net component instead of an application that does it (like Redgate) since it is much cheaper to distribute with the application.
Someone who knows some component?
best regards

I have this below code that generates BarCodes based on values from my MSHFlexgrid1 while the picture is in a PictureBox ("Picture1")

 when run in the IDE, I have each Picture related to the Value from my MSHFlexgrid1.
No issue
When i run it with the .exe, this is when i have the problem where the pictures don't match.
with issue
The code i have is:
  xlObj.ActiveWorkbook.ActiveSheet.range("A1") = "BARCODE"
    xlObj.ActiveWorkbook.ActiveSheet.range("B1") = "BARCODE VALUE"
    xlObj.ActiveWorkbook.ActiveSheet.Columns("A").ColumnWidth = 37.59

     With MSHFlexGrid1
        Dim gridRow As Long, xlRow As Long, LastRow As Long, xlDown As Long

        For gridRow = 1 To MSHFlexGrid1.Rows - 1
            If MSHFlexGrid1.TextMatrix(gridRow, 1) <> "" Then
                For xlRow = 2 To (MSHFlexGrid1.Rows - 1) + 1
                    If xlObj.ActiveWorkbook.ActiveSheet.Cells(xlRow, 2) = "" Then

                        Form1.Text1.Text = MSHFlexGrid1.TextMatrix(gridRow, 1)

                        SavePicture Picture1.Image, "C:\Pic.bmp"

                       ' Sleep 200 ' to

Open in new window

Big Business Goals? Which KPIs Will Help You
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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)
My Windows 10 laptop has an extension screen on its right hand side.

MyProject xl file should position a microsoft visio window precisely & dynamically over part of the xl Main window. The visio file is made into a child of the excel file, so whenever the xl file is moved around, the visio window moves along, ontop. This Parent-child relationship is stable and the visio window CANNOT move independently of the xl window.

I use the API and VBA code below to position the Visio window ontop of the xl window.

When I dynamically 'drag' MyProject xl window to change its dimensions, the xlWorkbookEvent: Private Sub Workbook_WindowResize(ByVal Wn As Window) calls Sub window_vis_setSize() [below] which recalculates the position of the visio window.

SUCCESS: This works perfectly WHEN MyProject xl is on my extension screen.
My PROBLEM: when MyProject xl (plus visio window) is dragged onto the laptop monitor, win10 automatically automatically shrinks the windows to fit the smaller laptop monitor.
However, the resizing calculation for the visio window overcompensates the required reduction in its size, making the visio window SHRINK relative to the Xl window, and to position inaccurately within the xl window.
But the PROBLEM is REVERSIBLE: When MyProject xl (plus visio window) is dragged FROM the laptop monitor ONTO the Extension monitor, the visio window reSizes & positions perfectly onto the xl window.

Please can you tell me/ point me toward solutions to this effect …

I would like to extract each barcode picture from my MSHFlexgrid1 into excel so that people can scan them.

Right now, it only extract the number and not the barcode itself.

How can i do the barcode extract?

Bacode in mshflexgrid1
This is the extract code i have.

  Dim xlObj As Object    'New Excel.Application -- only used with Excel reference
    Dim wkbOut As Object   'Excel.Workbook
    Dim wksOut As Object   'Excel.Worksheet
    Dim rngOut As Object   'Excel.Range
    Dim sngStart As Single    'forperformance measurement
    Dim start_time As Long
    Dim end_time As Long
    Dim total_time As Long
    Dim FileNm As Variant

    On Error Resume Next

    'Save file to
    With CommonDialog2
        .DialogTitle = "BarCode extract..."
        .FileName = Label3.Caption
        .CancelError = True  '<--moved
        '.Filter = "Excel Files (*.xls)|*.xls"
        ' .Filter = "Spreadsheet Files (*.xls)|*.xls| 2k7 Excel Files (*.xlsx)|*.xlsx"
        .Filter = "Spreadsheet Files (*.xls)|*.xls| 2k7 Excel Files (*.xlsx)|*.xlsx"

        If Err.Number = 32755 Then
            MsgBox "not saved - user pressed cancel or closed the dialog"
            Exit Sub
            FileNm = .FileName
            path_link = FileNm & ".xls"
        End If

    End With
    'output to Excel workbook
    '  lblStatus.Caption = "Begin Excel Data Export"
    Set xlObj = CreateObject("Excel.Application")
    Set wkbOut = xlObj.Workbooks.Add

Open in new window

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 …
The "store56_A" and "store57_A" are parameters that are returned from a stored procedure.  The problem is that in the return set, only one value is returned at a time, because the values are on different rows.  Meaning that store56_A and store57_A have a location ID that are the same, for example 25555 belongs to both store 56 and 57, but they have different amounts of items in each store, i.e. the "storecount".

I have tried the below VB6 code in an effort to write both values out to the same row in a csv file, however they both continue to come out on different rows within the file when created.  I am not sure if the problem is with the below code, or the store procedure, but the values returned in the SP seem to be correct.

if .fields("code").value = 56 and .fields("storecount") <> 0 then
      .fields("store56").value = .fields("store56_A").value
elseif .fields("code").value = 57 and .fields("storecount") <> 0 then
      .fields("store57").value = .fields("store57_A").value
.fields("store56").value = 0
.fields("store57").value = 0
end if

The store procedure has these values that are returned:

SELECT skuitem, storelocation, storecount_total, description, b.storecount as store56_A, c.storecount as store57_A
From products a
Inner Join storeitems b ON a.skuitem = b.skuitem
Inner Join storeitems c ON a.skuitem = c.skuitem
Where a.storelocation = b.storelocation

Products Table

Name      skuitem      Storecount_total      storelocation
Oklahoma      25555      3400      56
I had a GREAT spreadsheet until I added some lines and columns.  

In the account number fields (found throughout) when you entered 1234
you got 1234-00-00
When you entered 12
you got 1200-00-00
When you entered 123456
you got 1234-56-00

Suddenly, not only is that routing not working, once active content is enable, any entry to a custom or numeric field gets a Debug error. Sample spreadsheet is attached.

I know the problem is in VBA, but even when I update the routine with the appropriate cell numbers, ranges, I still get the error.

On how to Pragmatically Click
"5 Hours" in the timing TAB of the site below.
the default is "Hourly"

this is the site


Javascript  example
that i could use with
Set IE = CreateObject("InternetExplorer.Application")
and VB6


any example I  could  implement from VB6
currently i have a web-browser control

Thank You
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.
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!

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.
I'm using the below code to delete outlook items wit xlsx attachments. The issue encountered is that only some of the emails are deleted. Any thoughts

On Error GoTo SaveAttachmentsToFolder_err

    Dim ns As NameSpace
    Dim Inbox As Outlook.MAPIFolder
    Dim Item As Object
    Dim Atmt As Outlook.Attachment
    Dim FileName As String
    Dim SubFolder As MAPIFolder
    Set ns = GetNamespace("MAPI")

    Set recip = ns.CreateRecipient("OMHA.HQ.MI.REPORTS")
    Set Inbox = ns.GetSharedDefaultFolder(recip, olFolderInbox)
    Set SubFolder = Inbox.Folders("MATS")

    If SubFolder.Items.Count = 0 Then
        MsgBox "There are no messages with attachments in the MATS folder.", vbInformation, _
                "Nothing Found"
        Exit Sub
    End If

    'Delete Outlook items
    For Each Item In SubFolder.Items
    For Each Atmt In Item.attachments
    If Atmt.Type = 1 And InStr(Atmt, "xlsx") > 0 Then
    End If
    Next Atmt
    Next Item
    ' Clear memory
    Set Atmt = Nothing
    Set Item = Nothing
    Set ns = Nothing
    Exit Sub
' Handle Errors
    MsgBox "An unexpected error has occurred." _
        & vbCrLf & "Please note and report the following information." _
        & vbCrLf & "Macro Name: GetAttachments" _
        & vbCrLf & "Error Number: " & Err.Number _
        & vbCrLf & "Error Description: " & 

Open in new window

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

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/>

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.