Vba Basic Flashcards

1
Q

insert row

A

Rows(i & “:” & i ).Insert Shift:=xlDown

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

delete row

A

Rows(i & “:” & i).Delete shift:=xlUp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

export table DB

A

Call JDdumpvariable2d(output,false)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

open XML:

A

Workbooks.OpenXML “C:\TEMP\AMF\feedback_20150116.xml”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

convert column number to letter

A

ColumnLetter = Split(Cells(1, ColumnNumber).Address, “$”)(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Loop function:

A

in RealTimeFunction

Application.OnTime Now + TimeValue(“00:00:10”), “RealTimeFunction”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

save PDF:

A

ActiveSheet.Range(“B1:H60”).ExportAsFixedFormat Type:=xlTypePDF, fileName:=myFileName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

insert image from net:

A

Sheets(1).Shapes.AddPicture “http://www.testsite.com/pix/temp1.png” , msoFalse, msoTrue, 100, 100, 500, 600

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

send email:

A
Dim olMail As Object
Dim OlApp As Object
Set OlApp = CreateObject("Outlook.Application")
Set OlMail = OlApp.CreateItem(0)
With OlMail
    .To = myTo
    .Subject = mySubject
    '.Body = myBody
    .htmlBody = myHTMLbody
    .Attachments.add myfullPath
    .Display
End With
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

is file there:

A

isFileThere = (Dir(fileName) <> “”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

is Folder Exist

A

isFileThere = (Dir(myPath, vbDirectory) <> “”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

find all Files in folder:

A
fileName = Dir(myPath &amp; "*.*")
Do While fileName <> ""
   'code
   fileName = Dir()
Loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

try to create folder

A

On Error Resume Next
‘create folder
mkdir Location
On Error Goto 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

checkOpenFileName

A

Dim Wb As Workbook
For Each Wb In Workbooks
If InStr(Wb.Name, myFileName) <> 0 Then ‘found it
Next Wb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

change in Worksheet event:

A

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
mycolumn = Target.Cells.Column
myline = Target.Cells.Row

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

change in selection event

A

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

17
Q

Color a cell in red than back to blank

A

Cells(1, 1).Interior.Color = 255

Cells(1, 1).Interior.Color = xlNone

18
Q

Open Workbook

A

Workbooks.Open myPathFileName

19
Q

init Userform

A

Sub UserForm_Initialize()

20
Q

Copy file from one location to another and rename it

A

FileCopy oldDirectory & OldFileName, newDirectory & NewFileName

21
Q

get a random number 0-100

A

Randomize

mynum = Application.RoundUp(Rnd() * 100, 0)

22
Q

Read a text file line by line

A
Dim fs, f As Variant
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile(pathFileName, 1, , 0)
 While f.atendofline = False
        sloc = f.readline
'do things
Wend
f.Close
23
Q

Open text file to append it

A

Sub OpenTextFileTest
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Set fs = CreateObject(“Scripting.FileSystemObject”)
Set f = fs.OpenTextFile(“c:\testfile.txt”, ForAppending, TristateFalse)
f.Write “Hello world!”
f.Close
End Sub

24
Q

Connect to DB

A
Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sConnString As String
    Dim oCmd As ADODB.Command
sConnString = "..."
    Set conn = New ADODB.Connection
    conn.CommandTimeout = 60
    Set rs = New ADODB.Recordset
If left(UCase(mysql), 6) = "SELECT" Then
        Set rs = conn.Execute(mysql)
        If Not rs.EOF Then Call JDrstomat(rs, result)
    Else
        Set oCmd = New ADODB.Command
        With oCmd
            .ActiveConnection = conn
             .CommandType = adCmdText
            .CommandText = mysql
            .Execute , , adExecuteNoRecords
        End With
End If
25
Q

Format the column M with number comma separation

A

Columns(“M:M”).NumberFormat=“#,##0”

26
Q

Risize columns

A

Columns(A:B).EntireColumn.Autofit

27
Q

Remove autocorrect

A

Application.autocorrect.replacetext=false

28
Q

Email on behalf of someone

A

Set OutMail = OutApp.CreateItem(0)

Set OutMail.SendUsingAccount = OutApp.Session.Accounts.Item(“xxx@xxx.com”)