Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

VS 2012 VBA to VB.net syntax conversion Part 4

$
0
0
I wrote code in VBA (for a userform) and needed converted into V.B. The data collected from the userform will then be exported into an excel spreadsheet.
Already went to my resources and added Microsoft excel 14.0 object library and then I added the Microsoft.office.interop.

Code:

'Code occurs once OK command is clicked
Private Sub CmdOK_Click()

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

'Export Data to worksheet
With Selection
    .HorizontalAlignment = xlCenter
    Selection.NumberFormat = "00000"
    Call Borders
End With
Cells(emptyRow, 1).Value = LblDateCodeInput
Cells(emptyRow, 2).Value = TxtBxMtLtNum.Text
Cells(emptyRow, 3).Value = CmbTieSize.Column
Cells(emptyRow, 4).Value = LblTieColorDisplay
With Selection
    .HorizontalAlignment = xlCenter
    Selection.NumberFormat = "000"
    Call Borders
End With
Cells(emptyRow, 5).Value = TxtWeight.Value
Cells(emptyRow, 6).Value = TxtLength.Value
If OptionButton1 = True Then
    With Cells(emptyRow, 7)
        .Value = "#1    " & ChrW(&H2713)
        .HorizontalAlignment = xlDistributed
    End With
Else
    With Cells(emptyRow, 7)
        .Value = "#1    " & "X"
        .HorizontalAlignment = xlDistributed
    End With
End If

Cells(emptyRow, 8).Value = TxtTrvl.Value & Chr(34)
If OptionButton5 = True Then
    Cells(emptyRow, 9).Value = ChrW(&H2713)
Else
    Cells(emptyRow, 9).Value = "X"
End If
If OptionButton5 = True Then
    Cells(emptyRow, 10).Value = ChrW(&H2713)
Else
    Cells(emptyRow, 10).Value = "X"
End If
Cells(emptyRow, 11).Value = TextBox4.Value
ThisWorkbook.Save
Unload Me
End Sub

Am I wrong when I say that this code will have to be rewritten? Thanks for your help.

Just in case anyone asks, I am redoing this program with v.b. because there are certain professional looking features that v.b. has to offer. Also, not all versions of excel offer features like "Datepicker" or "Monthcalendar" in their VBA developer but the information still needs to be in an excel. A pain, I know.

Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>