Showing posts with label vba. Show all posts
Showing posts with label vba. Show all posts

Monday, February 27, 2017

Excel 2013 error; [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Based on your description, your Windows system is 64-bit and your Office is 32-bit.

I suggest you refer to this support article first:
https://msdn.microsoft.com/en-us/library/ms712362(v=vs.85).aspx

As the article said: To manage a data source that connects to a 32-bit driver under 64-bit platform, use :\windows\sysWOW64\odbcad32.exe.
To manage a data source that connects to a 64-bit driver, use :\windows\system32\odbcad32.exe.

Make sure that you create your ODBC link using the 32 bits ODBC Manager: C:\Windows\SysWOW64\odbcad32.exe
Source...

Saturday, February 04, 2017

VBA Excel - Using CreateObject

There are some very useful libaries that are not part of Excel VBA.
These include the Dictionary, Database objects, Outlook VBA objects, Word VBA objects and so on.

These are written using COM interfaces.
The beauty of COM is that was can easily use these libraries in our projects.

If we add a reference to the library we create the object in the normal way.

' Select Tools->References and place a check
' beside "Microsoft Scripting Runtime"
Dim dict As New Scripting.Dictionary

If we don’t use a reference we can create the object at run time using CreateObject.

Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")

The first method is referred to as Early Binding and the second is referred to as Late Binding(see Early versus Late Binding) for more details.

http://excelmacromastery.com/vba-objects/#Subtle_Differences_of_Dim_Versus_Set

Saturday, January 04, 2014

VB function : Clean Up / Remove HTML XML code from String

This function is removing all HTML/XML code from some string.
Private Function CodeClean(ByVal DStr As String) As String
Dim i As Long, j As Long
Dim Chr1 As String, Chr2 As String
Dim FlBol As Boolean
  Chr1 = "<"
  Chr2 = ">"

  If InStr(DStr, Chr1) > 0 Then FlBol = True Else FlBol = False
 
  Do Until FlBol = False
    i = 0
    j = 0
    i = InStr(DStr, Chr1)
    j = InStr(DStr, Chr2)
    If i > 0 And j = 0 Then
      j = Len(DStr)
    End If
    DStr = Left(DStr, i - 1) & Right(DStr, Len(DStr) - j)
    If InStr(DStr, Chr1) > 0 Then FlBol = True Else FlBol = False
  Loop
  Code Clean = DStr
End Function

You may change variables Chr1 & Chr2 to fit your need.

Saturday, December 28, 2013

Crack Hacking Password Microsoft Excel Macro VBA Project

There is another (somewhat easier) solution, without the size problems. I used this approach today (on a 2003 XLS file, using Excel 2007) and was successful.

  1.     Backup the xls file
  2.     Using a HEX editor, locate the DPB=... part
  3.     Change the DPB=... string to DPx=...
  4.     Open the xls file in Excel
  5.     Open the VBA editor (ALT+F11)
  6.     the magic: Excel discovers an invalid key (DPx) and asks whether you want to continue loading the project (basically ignoring the protection)
  7.     You will be able to overwrite the password, so change it to something you can remember
  8.     Save the xls file*
  9.     Close and reopen the document and work your VBA magic!

*NOTE: Be sure that you have changed the password to a new value, otherwise the next time you open the spreadsheet Excel will report errors (Unexpected Error), then when you access the list of VBA modules you will now see the names of the source modules but receive another error when trying to open forms/code/etc. To remedy this, go back to the VBA Project Properties and set the password to a new value. Save and re-open the Excel document and you should be good to go!

http://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project

My personal Note : Those methods written above is not applicable for .xlsm file. The easiest way is "save as" the file into old version .xls file. After that follow the methods above.

Wednesday, May 24, 2006

Show Open Dialog using Windows API

Dalam VB6 fungsi yang paling sering digunakan adalah Open File Dialog. Nah selain menggunakan menu manager yang terinstall di dalam VB, kita juga bisa langsung menggunakan Function yang telah ada pada Windows API. Untuk coding lengkapnya bisa di lihat di bawah ini :
'------------------------------------
Option Explicit
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_EXPLORER = &H80000
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Function BukaFileDlg(ByRef FileResult() As String, ByVal MultiSelect As Boolean, _
Optional ByVal DialogTitle As String = "", Optional ByVal FileFilter As String = "", _
Optional ByVal InitDir As String = "") As Boolean
Dim oFn As OPENFILENAME
Dim Stat As Long
Dim DefFilter As String
Dim Result As String
Dim ResultDir As String
Dim ResultFile As String
Dim ArrTmp() As String
Dim EndPos As Integer
Dim i As Integer
On Error GoTo errBukaFileDlg
'Preparing Dialog Environment
DefFilter = "All Files (*.*)" & Chr(0) "*.*"
If Len(FileFilter) > 0 Then DefFilter = FileFilter

oFn.lStructSize = Len(oFn)
oFn.hwndOwner = Form1.hWnd
oFn.hInstance = App.hInstance
oFn.lpstrFilter = DefFilter
oFn.lpstrFile = String$(1024, 0)
oFn.nMaxFile = 255
oFn.lpstrFileTitle = oFn.lpstrFile
oFn.nMaxFileTitle = oFn.nMaxFile
oFn.lpstrInitialDir = InitDir
oFn.lpstrTitle = DialogTitle
If MultiSelect Then
oFn.flags = OFN_ALLOWMULTISELECT Or OFN_EXPLORER
Else
oFn.flags = 0
End If
Stat = GetOpenFileName(oFn)
'Exit when Cancel Pressed
If Stat = 0 Then
BukaFileDlg = False
Exit Function
End If
BukaFileDlg = True
'Proccesing Output file into Array
Result = oFn.lpstrFile
ResultDir = Mid(Result, 1, oFn.nFileOffset - 1)
EndPos = InStr(oFn.lpstrFile, Chr$(0) & Chr$(0)) - 1
If EndPos <>
EndPos = Len(Result)
End If
ResultFile = Mid((Result), oFn.nFileOffset + 1, EndPos - oFn.nFileOffset)
ArrTmp = Split(ResultFile, vbNullChar)
For i = 0 To UBound(ArrTmp)
ArrTmp(i) = ResultDir & "\" & ArrTmp(i)
Next i
FileResult = ArrTmp
Exit Function
errBukaFileDlg:
BukaFileDlg = False
MsgBox Err.Number & "-" Err.Description, vbCritical, DialogTitle
End Function
'------------------------------
Mudah bukan?? Any questions are very welcome. :)