::: 까만콩 빈이네 :::
까만콩 빈이네의 살아가는 이야기를 기록합니다
RSS
  • Home

팁

20160218175029

2월 18 2016

[엑셀] – 바코드, 터치 스크린, DAO를 이용한 창고 관리

 

간이 재고관리이지만 코드가 길어서 그냥 아래 팁들을 올립니다.
바코드 리더를 이용 입력하고, 터치스크린으로 숫자를 누를 때마다
그 숫자를 텍스트 박스로 숫자 입력을 가능하게 하는 루틴입니다.
Option Explicit

Function Touch_Btn(obj1 As Object, obj2 As Object) As Integer

Select Case obj1.Caption

Case “1”
obj2.Value = Val(obj2.Text + “1”)

Case “2”
obj2.Value = Val(obj2.Text + “2”)

Case “3”
obj2.Value = Val(obj2.Text + “3”)

Case “4”
obj2.Value = Val(obj2.Text + “4”)

Case “5”
obj2.Value = Val(obj2.Text + “5”)

Case “6”
obj2.Value = Val(obj2.Text + “6”)

Case “7”
obj2.Value = Val(obj2.Text + “7”)

Case “8”
obj2.Value = Val(obj2.Text + “8”)

Case “9”
obj2.Value = Val(obj2.Text + “9”)

Case “0”
obj2.Value = Val(obj2.Text + “0”)

End Select

End Function
그리고 두번째 팁으로 ◀버튼을 누를 때마다 마지막 숫자를 지워서 다시
입력할 수 있도록 하는 팁입니다.

Private Sub Del_Last_Input()

Dim TempStr As String

If Len(TextBox4.Text) > 0 Then

TempStr = Left(TextBox4.Text, Len(TextBox4.Text) – 1)
TextBox4.Text = TempStr

End If

End Sub

나머지는 코드가 거의 1천여줄이라 엑셀파일을 제 블로그에 첨부해 두겠습니다.
찬찬히 훓어보시면 이해가 가시리라 봅니다. 거의 예제 수준이므로 공부하는데
도움이 되었으면 합니다.

 

첨부 : Manage_Stock

By vinipapa • 무른모 • 0 • Tags: DAO, 바코드, 엑셀, 창고관리, 터치스크린, 팁

20160217093310

2월 17 2016

[엑셀] – 각 워크북의 특정 시트의 특정열 병합

 

오랜만에 자료 올리네요. 기존에 내용이 있어서 쉽게 만들 수 있었네요.

Option Explicit

Sub MergeWBs()

Dim wbDst As Workbook
Dim wbSrc As Workbook

Dim wsSrc As Worksheet

Dim MyPath As String
Dim strFilename As String

Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False

MyPath = “C:\Data”

Set wbDst = ThisWorkbook

strFilename = Dir(MyPath & “\*.xls”, vbNormal)

If Len(strFilename) = 0 Then Exit Sub

Do Until strFilename = “”

Set wbSrc = Workbooks.Open(Filename:=MyPath & “\” & strFilename)

Set wsSrc = wbSrc.Worksheets(1)

wsSrc.Copy after:=wbDst.Worksheets(wbDst.Worksheets.Count)

wbSrc.Close False

strFilename = Dir()

Loop

wbDst.Worksheets(1).Delete

Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

Sub MergeWSs()

Dim wrk As Workbook

Dim sht As Worksheet
Dim trg As Worksheet

Dim rng As Range
Dim colCount As Integer

Set wrk = ActiveWorkbook

Application.DisplayAlerts = False

For Each sht In wrk.Worksheets
If sht.Name = “Master” Or sht.Name = “ExtData” Then

sht.Delete

End If
Next sht

Application.DisplayAlerts = True
Application.ScreenUpdating = False

Set trg = wrk.Worksheets.Add(after:=wrk.Worksheets(wrk.Worksheets.Count))
trg.Name = “ExtData”
Set sht = wrk.Worksheets(1)

With trg.Cells(1, 1).Resize(1, 3)
.Value = sht.Cells(1, 1).Resize(1, 3).Value

.Font.Bold = True
.Interior.Color = vbGreen
End With

For Each sht In wrk.Worksheets
If sht.Index = wrk.Worksheets.Count Then
Exit For
End If

Set rng = sht.Range(sht.Cells(31, 1), sht.Cells(31, 1).Resize(, 4))

trg.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count, 3).Value = rng.Value

Next sht

trg.Activate

trg.Columns.AutoFit

Application.ScreenUpdating = True

End Sub

 

차근 차근 읽어보시면 이해가 되실 것입니다.

첨부 : 20160217-각 워크북의 특정 시트의 특정열 병합

 

By vinipapa • 무른모 • 0 • Tags: 병합, 엑셀, 추출, 팁

20151006151939

10월 6 2015

엑셀(EXCEL) – 워드(Word)의 연동을 통한 사용자 정의 사전 구현(기능 다수 추가)

 

http://www.clien.net/cs2/bbs/board.php?bo_table=lecture&wr_id=290227
(엑셀(EXCEL) – 엑셀(Excel)과 워드(Word)의 연동을 통한 사용자 정의 사전 구현)

팁으로 올렸던 것을 이왕이면 실제 사용할 수 있고 편하게 사용하고자 수정해서 올립니다.
기존 것은 단순히 Excel에서 입력하고 Word에서 조회만 가능해서 두 프로그램을 실행하여
추가, 삭제 등을 해야 했으나 이 업그레이드 버전은 엑셀 파일을 열지않고 Word에서 단어들을
바로 추가, 수정 및 영문을 번역 단어로 전체 대치를 할 수 있도록 수정했습니다.

그리고 단어를 선택해서 바로 유저폼에서 조회할 수 있도록 하였습니다. 오른쪽 버튼을 누르면
팝업 메뉴를 구현(이것은 구걸…)하여 편의성을 올렸습니다. 일반적인 직장인?분이 MySQL이나
기타 DataBase프로그램을 이용하면 쉬울 것이라고 하지 말아주세요. 몰라서 안하는 것이 아니라
순수하게 Office Suite를 이용해서 이런 것도 할 수 있다는 것을 보여주는 것이기 때문입니다.

단어 대치 기능은 개별로 선택된 단어를 대치할 수도 있고 아래 붉은 글씨의 주의사항대로
문서 전체에서 등록된 단어들로 대치하는 기능입니다. 되돌릴 수 없는 기능이니 주의하세요.
쓰다 보니 되돌리기 기능이 너무 쉬워서 추가했습니다 ㅠㅠ.

Option Explicit

Private Sub CommandButton1_Click()

Dim i As Long

Dim fstr As String, sqlstr As String

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sConnString As String

‘ 연결 문자열 : Excel 2003
sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;excel 8.0;DATABASE=C:\UserDic.xls;”

‘ 새로운 연결과 레코드셋 설정
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset

‘ 연결
conn.Open sConnString

If Len(UserForm1.TextBox1.Text) = 0 Then Exit Sub

fstr = “%” & UserForm1.TextBox1.Text & “%”

sqlstr = “select Word, Trans, Mean from [DicList$] where Word like ‘” & fstr & “‘”

Set rst = conn.Execute(sqlstr)

‘ 데이터 체크
‘ 없으면 서브루틴 빠져 나감
If rst.BOF Or rst.EOF Then
UserForm1.ListBox1.Clear
Exit Sub

End If

rst.MoveFirst

i = 0

With UserForm1.ListBox1

.Clear

Do
.AddItem
.List(i, 0) = rst!Word
.List(i, 1) = rst!Trans
.List(i, 2) = rst!Mean

i = i + 1

rst.MoveNext

Loop Until rst.EOF

End With

‘ 연결 끊기와 메모리 비움
If CBool(conn.State And adStateOpen) Then conn.Close

Set conn = Nothing
Set rst = Nothing

End Sub

Private Sub CommandButton2_Click()

Dim i As Long

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sConnString As String

‘ 연결 문자열 : Excel 2003
sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;excel 8.0;DATABASE=C:\UserDic.xls;”

‘ 새로운 연결과 레코드셋 설정
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset

‘ 연결
conn.Open sConnString

Set rst = conn.Execute(“select Word, Trans, Mean from [DicList$] “)

‘ 데이터 체크
‘ 없으면 서브루틴 빠져 나감
If rst.BOF Or rst.EOF Then Exit Sub

rst.MoveFirst

i = 0

With UserForm1.ListBox1

.Clear

Do
.AddItem
.List(i, 0) = rst!Word
.List(i, 1) = rst!Trans
.List(i, 2) = rst!Mean

i = i + 1

rst.MoveNext

Loop Until rst.EOF

End With

‘ 연결 끊기와 메모리 비움
If CBool(conn.State And adStateOpen) Then conn.Close

Set conn = Nothing
Set rst = Nothing

‘ 검색할 값 초기화
TextBox1.Text = “”
TextBox2.Text = “”
TextBox3.Text = “”

End Sub

Private Sub CommandButton3_Click()

Dim sqlstr As String, fstr As String

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset

Dim sConnString As String

‘ 연결 문자열 : Excel 2003
sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;excel 8.0;DATABASE=C:\UserDic.xls;”

‘ 새로운 연결과 레코드셋 설정
Set conn = New ADODB.Connection

‘ 연결
conn.Open sConnString

fstr = Trim(UserForm1.TextBox1.Text)

If Len(fstr) = 0 Then Exit Sub

sqlstr = “SELECT * FROM [DicList$] WHERE Word='” & fstr & “‘”

Set rst = conn.Execute(sqlstr)

If rst.BOF Or rst.EOF Then

‘ 데이터 추가
sqlstr = “INSERT INTO [DicList$] VALUES (‘” & TextBox1.Text & “‘,'” &
TextBox2.Text & “‘,'” & TextBox3.Text & “‘)”

Call conn.Execute(sqlstr)
Else
MsgBox “동일 단어가 있습니다”

End If

‘ 연결 끊기와 메모리 비움
If CBool(conn.State And adStateOpen) Then conn.Close

Set conn = Nothing

TextBox1.Text = “”
TextBox2.Text = “”
TextBox3.Text = “”

Call CommandButton2_Click

End Sub

Private Sub CommandButton4_Click()

Dim sqlstr As String, fstr As String, frstr As String
Dim tstr As String, mstr As String

Dim conn As ADODB.Connection
Dim sConnString As String

‘ 연결 문자열 : Excel 2003
sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;excel 8.0;DATABASE=C:\UserDic.xls;”

‘ 새로운 연결과 레코드셋 설정
Set conn = New ADODB.Connection

‘ 연결
conn.Open sConnString

fstr = UserForm1.ListBox1.List(UserForm1.ListBox1.ListIndex, 0)

If Len(fstr) = 0 Then
MsgBox “단어를 선택하세요”
Exit Sub

End If

‘ 데이터 수정
frstr = UserForm1.TextBox1.Text
tstr = UserForm1.TextBox2.Text
mstr = UserForm1.TextBox3.Text

sqlstr = “UPDATE [DicList$] SET Trans = ‘” & tstr & “‘” & ” , Mean = ‘” & mstr & “‘” & ”
WHERE Word = ‘” & fstr & “‘”

Call conn.Execute(sqlstr)

‘ 디비를 변형적으로 업데이트
sqlstr = “UPDATE [DicList$] SET Word = ‘” & frstr & “‘” & ” WHERE Trans = ‘” & tstr &
“‘” & ” AND Mean = ‘” & mstr & “‘”

Call conn.Execute(sqlstr)

‘ 연결 끊기와 메모리 비움
If CBool(conn.State And adStateOpen) Then conn.Close

Set conn = Nothing

TextBox1.Text = “”
TextBox2.Text = “”
TextBox3.Text = “”

Call CommandButton2_Click

End Sub

‘ 개별 단어 대치
Private Sub CommandButton5_Click()

Dim myRange As Range

Set myRange = ActiveDocument.Content

myRange.Find.Execute FindText:=UserForm1.TextBox1.Text, MatchCase:=True,
MatchWholeWord:=True, _
ReplaceWith:=UserForm1.TextBox2.Text, Replace:=wdReplaceAll

End Sub

‘ 사전에 등록된 단어 전체 대치
Private Sub CommandButton6_Click()

Dim i As Integer

Dim myRange As Range

Set myRange = ActiveDocument.Content

For i = 0 To UserForm1.ListBox1.ListCount – 1

myRange.Find.Execute FindText:=UserForm1.ListBox1.List(i, 0), MatchCase:=True,
MatchWholeWord:=True, _
ReplaceWith:=UserForm1.ListBox1.List(i, 1), Replace:=wdReplaceAll

Next i

End Sub

‘ 사전에 등록된 단어 전체 환원
Private Sub CommandButton7_Click()

Dim i As Integer

Dim myRange As Range

Set myRange = ActiveDocument.Content

For i = 0 To UserForm1.ListBox1.ListCount – 1

myRange.Find.Execute FindText:=UserForm1.ListBox1.List(i, 1), MatchCase:=True,
MatchWholeWord:=True, _
ReplaceWith:=UserForm1.ListBox1.List(i, 0), Replace:=wdReplaceAll

Next i

End Sub

Private Sub ListBox1_Click()

TextBox1.Text = ListBox1.List(ListBox1.ListIndex, 0)
TextBox2.Text = ListBox1.List(ListBox1.ListIndex, 1)
TextBox3.Text = ListBox1.List(ListBox1.ListIndex, 2)

Call CopyToClip

End Sub
Module 하나를 추가해서 붙여넣기 합니다.

Option Explicit

Sub CopyToClip()

Dim obj As New DataObject
Dim Cliptxt As String

Cliptxt = UserForm1.ListBox1.List(UserForm1.ListBox1.ListIndex, 1)

obj.SetText Cliptxt

obj.PutInClipboard

End Sub
Sub Open_UserDic()

UserForm1.Show vbModeless

‘ 선택된 단어의 마지막 스페이스 문자 제거
UserForm1.TextBox1.Text = Trim(Selection.Text)

Dim i As Long

Dim fstr As String, sqlstr As String

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sConnString As String

‘ 연결 문자열 : Excel 2003
sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;excel 8.0;DATABASE=C:\UserDic.xls;”

‘ 새로운 연결과 레코드셋 설정
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset

‘ 연결
conn.Open sConnString

If Len(UserForm1.TextBox1.Text) = 0 Then Exit Sub

fstr = “%” & UserForm1.TextBox1.Text & “%”

sqlstr = “select Word, Trans, Mean from [DicList$] where Word like ‘” & fstr & “‘”

Set rst = conn.Execute(sqlstr)

‘ 데이터 체크
‘ 없으면 서브루틴 빠져 나감
If rst.BOF Or rst.EOF Then
UserForm1.ListBox1.Clear
UserForm1.TextBox2.Text = “”
UserForm1.TextBox3.Text = “”

Exit Sub

End If

rst.MoveFirst

i = 0

With UserForm1.ListBox1

.Clear

Do
.AddItem
.List(i, 0) = rst!Word
.List(i, 1) = rst!Trans
.List(i, 2) = rst!Mean

i = i + 1

rst.MoveNext

Loop Until rst.EOF

End With

‘ 연결 끊기와 메모리 비움
If CBool(conn.State And adStateOpen) Then conn.Close

Set conn = Nothing
Set rst = Nothing

End Sub

Sub BuildControls()

Dim oBtn As CommandBarButton

Dim oPopUp As CommandBarPopup
Dim oCtr As CommandBarControl

‘Make changes to the Normal template
CustomizationContext = NormalTemplate

‘Prevent double customization
Set oPopUp = CommandBars.FindControl(Tag:=”custPopup”)

If Not oPopUp Is Nothing Then GoTo Add_Individual

‘Add PopUp menu control to the top of the “Text” short-cut menu
Set oPopUp = CommandBars(“Text”).Controls.Add(msoControlPopup, , , 1)

With oPopUp
.Caption = “추가 기능”
.Tag = “custPopup”
.BeginGroup = True
End With

Set oBtn = oPopUp.Controls.Add(msoControlButton)

With oBtn
.Caption = “사용자 정의 사전”
.FaceId = 940
.Style = msoButtonIconAndCaption
.OnAction = “Open_UserDic”
End With

Set oBtn = Nothing

Add_Individual:
‘Or add individual commands directly to menu
Set oBtn = CommandBars.FindControl(Tag:=”custCmdBtn”)

If Not oBtn Is Nothing Then Exit Sub
‘Add control using built-in ID 758 (Boo&kmarks…)
Set oBtn = Application.CommandBars(“Text”).Controls.Add(msoControlButton, 758, , 2)

oBtn.Tag = “custCmdBtn”

If MsgBox(“This action caused a change to your Normal template.” _
& vbCr + vbCr & “Recommend you save those changes now.”, vbInformation +
vbOKCancel, _
“Save Changes”) = vbOK Then
NormalTemplate.Save
End If

Set oPopUp = Nothing
Set oBtn = Nothing

lbl_Exit:
Exit Sub

End Sub

Module 하나를 추가해서 붙여넣기 합니다. 코드가 충돌해서 Module을 분리하였습니다.

Option Explicit

Sub RemoveContent_MenuItem()

Dim oPopUp As CommandBarPopup
Dim oCtr As CommandBarControl

‘Make command bar changes in Normal.dotm
CustomizationContext = NormalTemplate

On Error GoTo Err_Handler

Set oPopUp = CommandBars(“Text”).Controls(“추가 기능”)

‘Delete individual commands on the PopUp menu
For Each oCtr In oPopUp.Controls
oCtr.Delete
Next

‘Delete the PopUp itself
oPopUp.Delete

‘Delete individual custom commands on the Text menu
For Each oCtr In Application.CommandBars(“Text”).Controls
If oCtr.Caption = “Boo&kmark…” Then
oCtr.Delete
Exit For
End If
Next oCtr

If MsgBox(“This action caused a change to your Normal template.” _
& vbCr + vbCr & “Recommend you save those changes now.”, vbInformation +
vbOKCancel, _
“Save Changes”) = vbOK Then
NormalTemplate.Save
End If

Set oPopUp = Nothing
Set oCtr = Nothing
Exit Sub

Err_Handler:

End Sub

추가> 문서 열고 닫을 때 사용자 정의 팝업 메뉴의 실행 및 제거 루틴이 빠졌어요.
저는 한 번 해서 계속 사용할 수 있어서 루틴을 깜빡 했습니다. 첨부된 화일에서 VBA Editor에서

ThisDocument 더블 클릭하시고 아래 코드 넣어세요.

Option Explicit

Private Sub Document_Close()

‘ 모듈이 오류가 나서  RemoveContentMenuItem를 RemoveContent_MenuItem로 바꾸세요.
Call RemoveContent_MenuItem

End Sub

Private Sub Document_Open()

Dim i As Long

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset

Dim sConnString As String
Dim sqlstr As String

‘ 연결 문자열 : Excel 2003
sConnString = “Provider=Microsoft.Jet.OLEDB.4.0;excel 8.0;DATABASE=C:\UserDic.xls;”

‘ 새로운 연결과 레코드셋 설정
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset

‘ 연결
conn.Open sConnString

Set rst = conn.Execute(“select Word, Trans, Mean from [DicList$] “)

‘ 데이터 체크
‘ 없으면 서브루틴 빠져 나감
If rst.BOF Or rst.EOF Then Exit Sub

rst.MoveFirst

i = 0

With UserForm1.ListBox1
.Clear

Do
.AddItem
.List(i, 0) = rst!Word
.List(i, 1) = rst!Trans
.List(i, 2) = rst!Mean

i = i + 1

rst.MoveNext

Loop Until rst.EOF

End With

‘ 연결 끊기와 메모리 비움
If CBool(conn.State And adStateOpen) Then conn.Close

Set conn = Nothing
Set rst = Nothing

‘ 사용자 정의폼을 모달리스 즉 플로팅 윈도우로 뛰어서
‘ 사용자가 수정,입력을 하면서 사전 참조할 수 있도록 함
UserForm1.Show vbModeless

‘ 사용자 편의를 위해 어짜피 영어 사전이므로 영어를 기본으로 입력하게 함
UserForm1.TextBox1.IMEMode = fmIMEModeAlpha

‘ 사용자 팝업 메뉴 생성
Call BuildControls

End Sub

수정 첨부 화일 : 20151006 – 워드(Word)의 연동을 통한 사용자 정의 사전 구현(기능 다수 추가)

By vinipapa • 무른모 • 0 • Tags: 사용자 정의 사전, 엑셀(EXCEL), 워드(Word), 팁

1 2 3

카테고리

  • 매킨토시 (261)
    • 굳은모 (73)
    • 무른모 (194)
  • 빈이네 (303)
    • 가족들 (107)
    • 까만콩 (60)
    • 엄마아빠 (131)
  • 잡동사니 (175)
    • 수다떨기 (37)
    • 정 보 (127)
    • 책읽기 (11)

그 밖의 기능

  • 로그인
  • 글 RSS
  • 댓글 RSS
  • WordPress.org

태그

AirPlay AirPrint Apple BootCamp bundle Database Design Dock Dropbox Edit Event Excel free iPad iPhone iTunes Limitted Free Mac Macbook Mac Bundle MacJournal Mac OSX Macupdate MobileMe OCR Pebble safari Sale share Snow Leopard software Tip tweet Twitter Update Windows 구입 나들이 맥 무료 빈이 업데이트 엑셀 엑셀(EXCEL) 팁
  • 2024 윤석열 탄핵 집회 참석
  • 맥 마이그레이션 중…
  • 동백
  • 같은 나무에 다른 색 잎 들
  • 여름 햇살

↑

© ::: 까만콩 빈이네 ::: 2025
Powered by WordPress • Themify WordPress Themes