Skip to content

Instantly share code, notes, and snippets.

@SeongilRyu
SeongilRyu / cnn_str.bas
Created March 4, 2019 03:44
ODBC Connection Strings
Public Function cnn_str(DB As String)
Dim cnnStr As String
Select Case DB
Case "AccessDB" '''
''("Provider = Microsoft.ACE.OLEDB.12.0; data source=" & "C:\CodeMiner\CodeMinerDb.accdb")
cnnStr = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & "C:\Users\Documents\DqExplorer" & "\" & "ppsdb.accdb"
Case "SqlExpress"
cnnStr = "driver={SQL Server};server=mynotebook\SQLEXPRESS;" & _
@SeongilRyu
SeongilRyu / sqlExplorer.bas
Last active March 4, 2019 04:01
Database and ODBC
Public Sub sqlExplorer()
Dim wb As New Workbook
Dim ws As New Worksheet
Set wb = ActiveWorkbook ''ThisWorkbook
Set ws = wb.Sheets("SqlExplorer")
Dim qry_text As Variant
Dim rngHeader As range
Dim rngResult As range
qry_text = range("qry_text").Value
@SeongilRyu
SeongilRyu / VBA_readWordTable.bas
Created February 1, 2019 03:46
VBA Read Cell Value of MS Word Table
Option Explicit
Public Sub read_word()
Dim wa As Word.Application
Dim wd As Word.Document
Dim wdtable As Word.Table
Dim wdFileName As Variant
Dim TableNo As Integer 'number of tables in Word doc
Dim iTable As Integer 'table number index
Dim iRow As Long 'row index in Excel
@SeongilRyu
SeongilRyu / VBA_arrays.bas
Last active January 13, 2019 04:08
Arrays
Sub arrays_declare()
'방법 1 : Dim 사용
Dim arr1() 'Size 없이 선언
'방법 2 : Size를 지정하여 선언
Dim arr2(5) '사이트 5를 지정
'방법 3 : 'Array' 파라메터 사용
Dim arr3
arr3 = Array("사과","오렌지","포도")
@SeongilRyu
SeongilRyu / VBA_datetime.bas
Created January 9, 2019 06:13
Functions of Date and time
Sub show_datetime()
Dim adate As Variant
adate = Date
Debug.Print adate ''2019-01-09
Debug.Print Year(adate) ''2019
Debug.Print Month(adate) ''1
Debug.Print Day(adate) ''9
Debug.Print DateAdd("yyyy", 1, adate) ''2020-01-09
@SeongilRyu
SeongilRyu / VBA_strings.bas
Last active January 9, 2019 06:17
Functions of String
Sub show_strings()
Dim str As String
str = "Microsoft VBA"
''1. InStr: 문자가 나타난 첫번째 위치
Debug.Print InStr(str, "VBA") ''Result= 11
''2. InStrRev: 역순으로 문자가 나타난 첫번째 위치
Debug.Print InStrRev(str, "VBA") ''Result= 11
''3. LCase: 소문자로 변경
Debug.Print LCase(str) ''Result= microsoft vba
Function fnc_add(width As Integer, height As Integer)
''함수 예제
Dim 가로 As Integer
Dim 세로 As Integer
Dim 면적 As Integer
가로 = width
세로 = height
면적 = 가로 * 세로
@SeongilRyu
SeongilRyu / VBA_procedure.bas
Last active January 5, 2019 06:57
VBA Procedure
Public Sub prc_add()
''프로시져 예제
Dim 가로 As Integer
Dim 세로 As Integer
Dim 면적 As Integer
가로 = 3
세로 = 4
면적 = 가로 * 세로