<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5768677426437492644</id><updated>2025-05-17T04:28:02.212+03:00</updated><category term="Microsoft DNS live sync MySQL WMI"/><category term="embed vbscript exe compile wrapper"/><category term="excel autofill double click vba"/><category term="excel macro password manager dictionary attack"/><category term="excel macro sum count countblank automatic"/><category term="excel password remover crack forgotten reset free freeware"/><category term="excel save jpg picture vba"/><category term="excel vba speed up"/><category term="runas password utility download source code C#"/><category term="vba excel last cell"/><category term="vbscript wmi usb insert remove connect"/><category term="word excel table export import vba"/><category term="word password crack remove reset freeware free"/><title type='text'>Code samples</title><subtitle type='html'>C#, VBA for MS Office, VBScript, JavaScript and other programming languages.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-1372348713407741155</id><published>2011-08-01T10:52:00.002+03:00</published><updated>2011-08-01T11:39:03.677+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="embed vbscript exe compile wrapper"/><title type='text'>Embed and run VBscript. Convert VBScript to executable (C#)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;First Create empty console C# project.&lt;br /&gt;
&lt;br /&gt;
Next, add your script file to project&#39;s resources.&lt;br /&gt;
In VS2010 you can do it with:&lt;br /&gt;
RMB on project name-&amp;gt;Properties-&amp;gt;Resources-&amp;gt;Add Resource-&amp;gt;Add New Text File&lt;br /&gt;
&lt;br /&gt;
Now you can get script&#39;s content to save and run it.&lt;br /&gt;
Source code is quite simple:&lt;br /&gt;
&lt;br /&gt;
To reference script content I use: &lt;br /&gt;
&lt;pre class=&quot;cpp&quot; name=&quot;code&quot;&gt;Properties.Resources.MyEmbeddedScript&lt;/pre&gt;where MyMbeddedScript is name of resource.&lt;br /&gt;
&lt;br /&gt;
Get some random temporary file name:&lt;br /&gt;
&lt;pre class=&quot;cpp&quot; name=&quot;code&quot;&gt;string scriptFileName = Path.GetTempFileName().Replace(&quot;.tmp&quot;,&quot;.vbs&quot;);&lt;/pre&gt;&lt;br /&gt;
Next save and run script:&lt;br /&gt;
&lt;pre class=&quot;cpp&quot; name=&quot;code&quot;&gt;File.WriteAllText(scriptFileName, content);
startedProcess = Process.Start(scriptFileName);&lt;/pre&gt;&lt;br /&gt;
To run a script as other user you can use this method:&lt;br /&gt;
&lt;a href=&quot;http://vbacodesamples.blogspot.com/2011/07/runas-utility-without-password-prompt.html&quot;&gt;RunAs without password prompt&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Any other script (.js, .vbs, .ahk) can be easily embedded into .exe-file in this way. &lt;br /&gt;
&lt;br /&gt;
Full source code:&lt;br /&gt;
&lt;pre class=&quot;cpp&quot; name=&quot;code&quot;&gt;using System;
using System.Security;
using System.Diagnostics;
using System.IO;

namespace scriptEmbed
{
    class Program
    {
        static int Main(string[] args)
        {
            return RunScript(Properties.Resources.MyEmbeddedScript);
        }
        static int RunScript(string content)
        {
            string scriptFileName = Path.GetTempFileName().Replace(&quot;.tmp&quot;,&quot;.vbs&quot;);
            Process startedProcess;
            try
            {
                File.WriteAllText(scriptFileName, content);
                startedProcess = Process.Start(scriptFileName);
                
                while (!startedProcess.HasExited) ;

                File.Delete(scriptFileName);
                
                return startedProcess.ExitCode;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return 1;
            }
        }
        static string GetTempFolder()
        {
            return System.Environment.GetEnvironmentVariable(&quot;TEMP&quot;);
        }
    }

}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/1372348713407741155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2011/08/embed-and-run-vbscript-convert-vbscript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/1372348713407741155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/1372348713407741155'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2011/08/embed-and-run-vbscript-convert-vbscript.html' title='Embed and run VBscript. Convert VBScript to executable (C#)'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-8806522481495304796</id><published>2011-07-31T15:58:00.005+03:00</published><updated>2011-07-31T16:29:38.780+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="runas password utility download source code C#"/><title type='text'>RunAs without password prompt in C#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;This alternative of RunAs utility allows to specify a password in command line.&lt;br /&gt;
&lt;br /&gt;
It does same as standard runas.exe does. The only difference is you can specify your user password right in command line.&lt;br /&gt;
&lt;br /&gt;
It can be used by System Administrators in batch jobs to run tasks under admin account.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://sites.google.com/site/xedocfiles/files/runasuser.zip?attredirects=0&amp;amp;d=1&quot;&gt;Download RunAs Utility with password parameter in command line&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Syntax:&lt;br /&gt;
runasuser [-u user] [-p password] [-d domain] someprogram.exe [params] &lt;br /&gt;
&lt;br /&gt;
Here is full source code:&lt;br /&gt;
&lt;pre class=&quot;cpp&quot; name=&quot;code&quot;&gt;using System;
using System.Diagnostics;
using System.Security;

namespace RunAsUser
{
    class Program
    {
        static int Main(string[] args)
        {
            string username = &quot;&quot;, password = &quot;&quot;, domain = &quot;&quot;, apppath = &quot;&quot;, arguments = &quot;&quot;;

            for( int i=0; i&amp;ltargs.Length; i++)
            {
                switch (args[i].ToLower())
                {
                    case &quot;-u&quot;:
                        username = args[++i];
                        break;
                    case &quot;-p&quot;:
                        password = args[++i];
                        break;
                    case &quot;-d&quot;:
                        domain = args[++i];
                        break;
                    default:
                        if (apppath == &quot;&quot;)
                            apppath = args[i];
                        else
                            arguments += args[i] + (i&amp;ltargs.Length?&quot; &quot;:&quot;&quot;);
                        break;
                }
            }

            if (args.Length == 0 || apppath == &quot;&quot; )
            {
                Console.WriteLine(&quot;\nCommand line syntax:\nrunasuser [-u user] [-p password] [-d domain] someprogram.exe [params]\n&quot;);
                return 1;
            }
            Console.WriteLine(arguments);
            return RunAs(apppath, arguments, domain, username, password);

        }
        static int RunAs(string apppath, string arguments, string domain, string username, string password)
        {
            Process userProcess;
            try
            {
                userProcess = Process.Start( apppath, arguments, username, GetSecure(password), domain);
                while (!userProcess.HasExited) ;
                return userProcess.ExitCode;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return -1;
        }

        static SecureString GetSecure(string str)
        {
            SecureString SecureStr = new SecureString();
            foreach (char c in str)
            {
                SecureStr.AppendChar(c);
            }

            return SecureStr;
        }
    }
}&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/8806522481495304796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2011/07/runas-utility-without-password-prompt.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/8806522481495304796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/8806522481495304796'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2011/07/runas-utility-without-password-prompt.html' title='RunAs without password prompt in C#'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-6588630576224588726</id><published>2011-07-26T10:48:00.001+03:00</published><updated>2011-07-26T11:07:35.453+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Microsoft DNS live sync MySQL WMI"/><title type='text'>Microsoft DNS live sync to MySQL (VBScript)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Sometime its handy to have replica of DNS records in MySQL server. You can use this database to build some network diagrams, count computers etc.&lt;br /&gt;
&lt;br /&gt;
In this example I use WMI to synchronize Microsoft DNS database with MySQL server. &lt;br /&gt;
&lt;br /&gt;
This script makes complete snapshot of DNS database first. Then it set a handler for each event: Create/Modify/Delete. &lt;br /&gt;
&lt;div closure_uid_aw62dd=&quot;225&quot;&gt;Each event makes changes in MySQL database. This approach allow to have exact replica of DNS records in MySQL without visible delays.&lt;/div&gt;&lt;div closure_uid_aw62dd=&quot;212&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div closure_uid_aw62dd=&quot;189&quot; style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://sites.google.com/site/xedocfiles/files/dnsmonitor.zip?attredirects=0&amp;amp;d=1&quot;&gt;&lt;span closure_uid_aw62dd=&quot;213&quot; style=&quot;font-size: large;&quot;&gt;&lt;b closure_uid_aw62dd=&quot;224&quot;&gt;Download dnsmonitor.vbs script&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div closure_uid_aw62dd=&quot;189&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;You can find source code below.&lt;br /&gt;
Don&#39;t forget to change NetBios name of your server and MySQL credentials on top.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;&#39;Netbios name of DNS server
Const SERVERNAME = &quot;SERVER&quot;

&#39;MySQL credentials
Const host=&quot;localhost&quot;
Const Db=&quot;system&quot;
Const login= &quot;user&quot;
Const password=&quot;userpassword&quot;

&#39;MySQL connection options
Const MYDRIVER = &quot;MySQL ODBC 5.1 Driver&quot;
Const FLAG_BIG_PACKETS = 8 &#39;Allow big results
Const FLAG_NO_PROMPT = 16 &#39;Dont prompt anything
Const FLAG_DYNAMIC_CURSOR = 32 &#39;Allow dynamic cursor
Const FLAG_COMPRESSED_PROTO = 2048 &#39;Use compressed protocol
Const FLAG_NO_BIGINT = 16384 &#39;Change bigint(8) to int(4)
Const FLAG_MULTI_STATEMENTS = 67108864 &#39;Enable batch statements
Const FLAG_AUTO_RECONNECT = 4194304 &#39;Auto reconnect

&#39;ADODB connection
Dim conn

&#39;Create global objects
Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}\\&quot; &amp;amp; SERVERNAME &amp;amp; &quot;\root\MicrosoftDNS&quot;)
Set objSink = WScript.CreateObject(&quot;WBemScripting.SWbemSink&quot;,&quot;event_&quot;)
Set objShell = CreateObject(&quot;WScript.Shell&quot;)

&#39;Exit if already running
Set oProcess = Nothing
If alreadyRunning() Then: WScript.Quit

If Not MySQLConnect() Then
WScript.Quit
Else
PrepareDatabase
End If

&#39;Initialize mysql data once
MySQLExecute &quot;DELETE FROM dns_cache&quot;
Set dnsRecords = objWMIService.ExecQuery( &quot;SELECT * FROM MicrosoftDNS_AType&quot;, &quot;WQL&quot;, 48 )
For Each objRecord in dnsRecords
domain = objRecord.DomainName
name = Replace(objRecord.OwnerName,domain,&quot;&quot;)
ip = objRecord.IPAddress 
ttl = objRecord.TTL
timestamp = objRecord.Timestamp
OnCreation domain,name,ip,timestamp,ttl
Next

&#39;Set DNS event handler
objWMIService.ExecNotificationQueryAsync objSink, &quot;Select * from __InstanceOperationEvent within 1 where TargetInstance ISA &#39;MicrosoftDNS_AType&#39;&quot;

&#39;Infinite loop
Do
WScript.Sleep 1000
Loop

&#39;Events handler
Sub event_OnObjectReady( objEvent, objContext )
With objEvent
domain = objEvent.TargetInstance.DomainName
name = Replace(objEvent.TargetInstance.OwnerName,domain,&quot;&quot;)
ip = objEvent.TargetInstance.IPAddress 
ttl = objEvent.TargetInstance.TTL
timestamp = objEvent.TargetInstance.timestamp
if name &amp;lt;&amp;gt; &quot;&quot; Then
Select Case .Path_.Class
Case &quot;__InstanceModificationEvent&quot;
OnModify domain,name,ip,timestamp,ttl
Case &quot;__InstanceCreationEvent&quot;
OnCreation domain,name,ip,timestamp,ttl
Case &quot;__InstanceDeletionEvent&quot;
OnDeletion domain,name,ip
End Select
End If
End With
End Sub

&#39;Handler for modify event
Sub OnModify( domain, name,ip,timestamp,ttl )
update = &quot;domainname=&#39;&quot; &amp;amp; domain &amp;amp; &quot;&#39;,hostname=&#39;&quot; &amp;amp; name &amp;amp; &quot;&#39;,ipaddress=inet_aton(&#39;&quot; &amp;amp; ip &amp;amp; &quot;&#39;),&quot; &amp;amp; _ 
&quot;refreshon=IF(&quot; &amp;amp; timestamp &amp;amp; &quot;=0,Null,&#39;1601-01-01 00:00&#39;) + INTERVAL &quot; &amp;amp; timestamp &amp;amp; &quot; HOUR,ttl=&quot; &amp;amp; ttl
MySQLExecute &quot;INSERT INTO dns_cache SET &quot; &amp;amp; update &amp;amp; &quot; ON DUPLICATE KEY UPDATE &quot; &amp;amp; update
End Sub

&#39;Handler for create event
Sub OnCreation( domain, name,ip,timestamp,ttl )
update = &quot;domainname=&#39;&quot; &amp;amp; domain &amp;amp; &quot;&#39;,hostname=&#39;&quot; &amp;amp; name &amp;amp; &quot;&#39;,ipaddress=inet_aton(&#39;&quot; &amp;amp; ip &amp;amp; &quot;&#39;),&quot; &amp;amp; _
&quot;refreshon=IF(&quot; &amp;amp; timestamp &amp;amp; &quot;=0,Null,&#39;1601-01-01 00:00&#39;) + INTERVAL &quot; &amp;amp; timestamp &amp;amp; &quot; HOUR,ttl=&quot; &amp;amp; ttl
MySQLExecute &quot;INSERT INTO dns_cache SET &quot; &amp;amp; update &amp;amp; &quot; ON DUPLICATE KEY UPDATE &quot; &amp;amp; update 
End Sub

&#39;Handler for delete event
Sub OnDeletion( domain, name,ip )
MySQLExecute &quot;DELETE FROM dns_cache WHERE hostname=&#39;&quot; &amp;amp; name &amp;amp; &quot;&#39; AND ipaddress=inet_aton(&#39;&quot; &amp;amp; ip &amp;amp; &quot;&#39;) AND domainname=&#39;&quot; &amp;amp; domain &amp;amp; &quot;&#39;&quot;
End Sub

&#39;Create database and tables if it wasn&#39;t done
Function PrepareDatabase
CreateDatabase = False
On Error Resume Next
MySQLExecute &quot;CREATE DATABASE IF NOT EXISTS &quot; &amp;amp; db &amp;amp; &quot; CHARACTER SET utf8 COLLATE utf8_general_ci&quot;
On Error Goto 0
MySQLExecute &quot;USE &quot; &amp;amp; db
MySQLExecute &quot;CREATE TABLE IF NOT EXISTS dns_cache(&quot; &amp;amp; _
&quot;hostname VARCHAR(255) NOT NULL,&quot; &amp;amp; _
&quot;domainname VARCHAR(255) NOT NULL,&quot; &amp;amp; _
&quot;ipaddress INT(11) UNSIGNED NOT NULL,&quot; &amp;amp; _
&quot;refreshon DATETIME DEFAULT NULL,&quot; &amp;amp; _
&quot;ttl INT(11) NOT NULL DEFAULT 0,&quot; &amp;amp; _
&quot;PRIMARY KEY (ipaddress, hostname, domainname),&quot; &amp;amp; _
&quot;INDEX IX_dns_cache_deadline (refreshon),&quot; &amp;amp; _
&quot;INDEX IX_dns_cache_domainname (domainname),&quot; &amp;amp; _
&quot;INDEX IX_dns_cache_ipaddress (ipaddress),&quot; &amp;amp; _
&quot;INDEX IX_dns_cache_name (hostname),&quot; &amp;amp; _
&quot;INDEX IX_dns_cache_ttl (ttl)&quot; &amp;amp; _
&quot;) &quot; &amp;amp; _
&quot;ENGINE = INNODB &quot; &amp;amp; _
&quot;AVG_ROW_LENGTH = 68 &quot; &amp;amp; _
&quot;CHARACTER SET utf8 &quot; &amp;amp; _
&quot;COLLATE utf8_general_ci;&quot;
If Err.Number &amp;lt;&amp;gt; 0 Then: CreateDatabase = True
End Function

Function alreadyRunning()
alreadyRunning = False
wscrCount = ProcessCount( &quot;%wscript%&quot; &amp;amp; WScript.ScriptName &amp;amp; &quot;%&quot; )
cscrCount = ProcessCount( &quot;%cscript%&quot; &amp;amp; WScript.ScriptName &amp;amp; &quot;%&quot; )
If wscrCount &amp;gt; 1 or cscrCount &amp;gt; 1 Then:alreadyRunning = True
End Function

Public Function ProcessCount(likestr)
Set objWMI = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}\\.\root\cimv2&quot;)
Set colItems = objWMI.ExecQuery(&quot;SELECT Name,CommandLine FROM Win32_Process WHERE CommandLine Like &#39;&quot; &amp;amp; likestr &amp;amp; &quot;&#39;&quot;)
ProcessCount = colItems.Count
End Function 

&#39;MySQL routines
Function MySQLExecute( cmd )
On Error Resume Next
Set rst = conn.Execute( cmd )
If conn.Errors.Count &amp;gt; 0 Then
If conn.Errors(conn.Errors.Count-1).NativeError = 2006 Then 
conn.Errors.Clear
If InitConnection() Then
Set rst = conn.Execute( cmd )
End If
End If 
End If
If rst.State = 1 And Err.Number = 0 Then
Set MySQLExecute = rst
Else
Set MySQLExecute = conn.Execute( &quot;SELECT Null LIMIT 0&quot; )
End If
On Error Goto 0
End Function

Function MySQLConnect
Set conn = CreateObject(&quot;ADODB.Connection&quot;)
MySQLConnect = False
On Error Resume next
conn.ConnectionString = &quot;DRIVER={&quot; &amp;amp; MYDRIVER &amp;amp; &quot;};&quot; &amp;amp; _
&quot;SERVER=&quot; &amp;amp; host &amp;amp; &quot;;&quot; &amp;amp; _
&quot;UID=&quot; &amp;amp; login &amp;amp; &quot;;&quot; &amp;amp; _
&quot;PWD=&quot; &amp;amp; password &amp;amp; &quot;;&quot; &amp;amp; _
&quot;OPTION=&quot; &amp;amp; (FLAG_BIG_PACKETS + FLAG_COMPRESSED_PROTO + FLAG_NO_BIGINT + FLAG_MULTI_STATEMENTS)
conn.ConnectionTimeout = 3
conn.Open
If Err.Number = -2147467259 Then
MsgBox &quot;MyODBC isn&#39;t installed. Can&#39;t connect to MySQL!&quot;
Exit Function
End If
If Err.Number &amp;lt;&amp;gt; 0 Then
MsgBox err.description
Exit Function
End If
MySQLConnect = True
On Error GoTo 0
End Function

Sub MySQLDisconnect
conn.Close
Set conn = Nothing
End Sub&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/6588630576224588726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2011/07/microsoft-dns-live-sync-to-mysql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/6588630576224588726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/6588630576224588726'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2011/07/microsoft-dns-live-sync-to-mysql.html' title='Microsoft DNS live sync to MySQL (VBScript)'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-6073741045453636198</id><published>2011-07-16T16:55:00.004+03:00</published><updated>2011-07-17T15:50:39.422+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vbscript wmi usb insert remove connect"/><title type='text'>USB device insert/remove monitoring with VBScript</title><content type='html'>Some time ago I got an Android Phone. To manage it from PC I installed &lt;a href=&quot;http://www.fjsoft.at/en/&quot;&gt;MyPhoneExplorer.&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
Thats great software but it doesn&#39;t have one vital feature: reconnect automatically when phone is connected via USB. On other hand it have such an option as &quot;Connect on start&quot;.&lt;br /&gt;
So my idea was to write some program/script to kill MyPhoneExplorer&#39;s process on disconnect and start it on connect.&lt;br /&gt;
This script just sitting and watching when &quot;Android ADB Interface&quot; device get connected or disconnected via USB executing corresponding action on each event. &lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://sites.google.com/site/xedocfiles/files/usbevent.zip?attredirects=0&amp;amp;d=1&quot;&gt;Download VBS script&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Const DEVICENAME = &quot;Android ADB Interface&quot;
Const EXENAME = &quot;MyPhoneExplorer.exe&quot;
Dim lastOperation
Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}\\.\root\cimv2&quot;)

&#39;Exit if already running
If alreadyRunning() Then: WScript.Quit

Set objSink = WScript.CreateObject(&quot;WBemScripting.SWbemSink&quot;,&quot;event_&quot;)
Set objShell = CreateObject(&quot;WScript.Shell&quot;)
Set deviceIDs = CreateObject(&quot;Scripting.Dictionary&quot;)

&#39;Set event hook
objWMIService.ExecNotificationQueryAsync objSink, &quot;Select * from __InstanceOperationEvent within 1 where TargetInstance ISA &#39;Win32_PnPEntity&#39;&quot;

&#39;Get device IDs by name
EnumerateDevices DEVICENAME
objShell.Popup &quot;USB monitoring started&quot;,2
&#39;Infinite loop
Do
 WScript.Sleep 1000
Loop

&#39;USB insert/remove hook procedure
Sub event_OnObjectReady( objEvent, objContext )
 With objEvent
  If deviceIDs.Exists(.TargetInstance.DeviceId) Then
   Select Case .Path_.Class
    Case &quot;__InstanceCreationEvent&quot;
     If lastOperation &amp;lt;&amp;gt; &quot;Insert&quot; Then
      lastOperation = &quot;Insert&quot;
      OnInsert
     End If
      
    Case &quot;__InstanceDeletionEvent&quot;
     If lastOperation &amp;lt;&amp;gt; &quot;Remove&quot; Then
      lastOperation = &quot;Remove&quot;
      OnRemove
     End If
    End Select
  End If
 End With
End Sub

Sub OnInsert
 objShell.Run EXENAME,1,0
End Sub

Sub OnRemove
 objShell.Run &quot;taskkill /f /im &quot; &amp;amp; EXENAME,0,0
End Sub

Sub EnumerateDevices(name)
 Set objDevices = objWMIService.ExecQuery(&quot;SELECT DeviceId FROM Win32_PnPSignedDriver WHERE Description=&#39;&quot; &amp;amp; name &amp;amp; &quot;&#39;&quot;)
 For Each dev in objDevices
  deviceId = dev.DeviceId
  If Not deviceIDs.Exists(deviceId) Then
   deviceIDs.Add deviceId, deviceId
  End If
  d = d + 1
 Next
End Sub

Function alreadyRunning()
 alreadyRunning = False
 wscrCount = ProcessCount( &quot;%wscript%&quot; &amp;amp; WScript.ScriptName &amp;amp; &quot;%&quot; )
 cscrCount = ProcessCount( &quot;%cscript%&quot; &amp;amp; WScript.ScriptName &amp;amp; &quot;%&quot; )
 If  wscrCount &amp;gt; 1 or cscrCount &amp;gt; 1 Then:alreadyRunning = True
End Function

Public Function ProcessCount(likestr)
 Set colItems = objWMIService.ExecQuery(&quot;SELECT Name,CommandLine FROM Win32_Process WHERE CommandLine Like &#39;&quot; &amp;amp; likestr &amp;amp; &quot;&#39;&quot;)
 ProcessCount = colItems.Count
End Function   
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://sites.google.com/site/xedocfiles/files/usbevent.zip?attredirects=0&amp;amp;d=1&quot;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/6073741045453636198/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2011/07/usb-device-insertremove-monitoring-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/6073741045453636198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/6073741045453636198'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2011/07/usb-device-insertremove-monitoring-with.html' title='USB device insert/remove monitoring with VBScript'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-1530466694891961022</id><published>2010-02-04T18:01:00.003+02:00</published><updated>2010-02-04T18:03:35.939+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel save jpg picture vba"/><title type='text'>Excel Worksheet to picture using VBA (Jpeg, Png etc)</title><content type='html'>This sample will show how to automate export of Excel sheet to image file.&lt;br /&gt;
&lt;br /&gt;
You need to download and install&amp;nbsp;&lt;a href=&quot;http://www.imagemagick.org/script/binary-releases.php#windows&quot;&gt;ImageMagick library&lt;/a&gt; (Q16 version)&lt;br /&gt;
&lt;br /&gt;
When ImageMagick is installed you could use this code to save your Excel worksheet to picture (use &quot;view plain&quot; option to copy code to clipboard):&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Dim imObject As Object
&#39;Create ImageMagick Object
Set imObject = CreateObject(&quot;ImageMagickObject.MagickImage.1&quot;)
&#39;Copy selected area to clipboard as picture
Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
&#39;Save clipboard to image named c:\image.jpg
imObject.Convert &quot;clipboard:myimage&quot;, &quot;&quot;, &quot;-quality&quot;, &quot;85&quot;, &quot;c:\image.jpg&quot;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/1530466694891961022/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/02/excel-worksheet-to-picture-using-vba.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/1530466694891961022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/1530466694891961022'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/02/excel-worksheet-to-picture-using-vba.html' title='Excel Worksheet to picture using VBA (Jpeg, Png etc)'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-7349205229095129220</id><published>2010-02-04T16:15:00.000+02:00</published><updated>2010-02-04T16:15:08.335+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="word excel table export import vba"/><title type='text'>Export last table from Word to Excel</title><content type='html'>This sample will copy last table from each of given word documents to active sheet.&lt;br /&gt;
&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;vb&quot;&gt;Sub CopyTables()
Set appWord = CreateObject(&quot;Word.Application&quot;)
On Error GoTo emergencyexit
fileNames = Array(&quot;c:\1.doc&quot;,&quot;c:\2.doc&quot;)
For Each Filename In fileNames
    Set docWord = Nothing
    Set docWord = appWord.Documents.Open(Filename)
    If Not docWord Is Nothing Then
        docWord.tables(docWord.tables.Count).Select
        appWord.Selection.Copy
        ActiveSheet.Paste
        docWord.Close
        ActiveSheet.UsedRange.Offset(ActiveSheet.UsedRange.Rows.Count).Resize(1, 1).Select
    End If
Next
emergencyexit:
appWord.Quit

End Sub&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/7349205229095129220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/02/export-last-table-from-word-to-excel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/7349205229095129220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/7349205229095129220'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/02/export-last-table-from-word-to-excel.html' title='Export last table from Word to Excel'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-5823788086856362541</id><published>2010-02-04T11:24:00.008+02:00</published><updated>2010-02-05T13:31:35.811+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel autofill double click vba"/><title type='text'>Excel Autofill VBA emulation</title><content type='html'>This code emulates double click on bottom right&amp;nbsp; corner of selected cell. &lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Sub Autofill()
    On Error Resume Next
    Dim checkRange As Range
    
    If RangeState(Selection) = 2 Then: Exit Sub
    
    selMaxRow = Selection.Row + Selection.Rows.Count - 1
    selColsCount = Selection.Columns.Count
    selRowsCount = Selection.Rows.Count
    usedRows = ActiveSheet.UsedRange.Rows.Count
    maxrow = selMaxRow
    row_offset = 0
        
    checkLeft = False
    checkRight = False
    checkCenter = False
    If Selection.Column &gt; 1 Then
        If RangeState(Selection.Offset(0, -1).Resize(selRowsCount, 1)) = 1 Then
            checkLeft = True
        End If
    End If
    If Not checkLeft Then
        If (Selection.Column + selColsCount) &lt; ActiveSheet.Cells.Columns.Count Then
            If RangeState(Selection.Offset(0, selColsCount).Resize(selRowsCount, 1)) = 1 Then: checkRight = True
        End If
    End If

    Set checkRange = Selection.Offset(selRowsCount).Resize(1, selColsCount)
    
    If Not checkLeft And Not checkRight Then
        If RangeState(checkRange) = 1 Then: checkCenter = True
    Else
        checkCenter = True
    End If
    
    For row_offset = 0 To usedRows - Selection.Row - selRowsCount
        If (selMaxRow + row_offset) &lt; usedRows And checkCenter Then
            tmp = RangeState(checkRange.Offset(row_offset))
            If row_offset = 0 Then: center_state = tmp
            If tmp &lt;&gt; center_state Then: checkCenter = False
            If center_state = 3 Then: checkCenter = False
        End If
        
        If checkLeft And center_state = 2 Then
            left_state = RangeState(checkRange.Offset(row_offset, -1).Resize(1, 1))
            If left_state = 2 Or left_state = 3 Then: Exit For
        ElseIf checkRight And center_state = 2 Then
            right_state = RangeState(checkRange.Offset(row_offset, selColsCount).Resize(1, 1))
            If right_state = 2 Or right_state = 3 Then: Exit For
        End If
                
        If checkCenter Then: maxrow = maxrow + 1
    Next
    
    If maxrow &gt; selMaxRow Then
        Selection.Autofill Destination:=Selection.Resize(maxrow - (Selection.Row) + 1)
        Selection.Resize(maxrow - Selection.Row + 1).Select
    End If
End Sub


Function RangeState(rng As Range)
    RangeState = 0
    If IsArray(rng.Formula) Then
        For Each Formula In rng.Formula
            If Formula &lt;&gt; &quot;&quot; Then
                RangeState = RangeState Or 1
            Else
                RangeState = RangeState Or 2
            End If
        Next
    Else
        If rng.Formula &lt;&gt; &quot;&quot; Then
            RangeState = 1
        Else
            RangeState = 2
        End If
    End If
End Function&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/5823788086856362541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/02/excel-autofill-vba-emulation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/5823788086856362541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/5823788086856362541'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/02/excel-autofill-vba-emulation.html' title='Excel Autofill VBA emulation'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-1230836252313236663</id><published>2010-01-23T12:41:00.000+02:00</published><updated>2010-01-23T12:41:29.367+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel macro password manager dictionary attack"/><title type='text'>Excel Dictionary Password Attack macro</title><content type='html'>This&amp;nbsp;xla add-in&amp;nbsp;uses dictionary to recover&amp;nbsp;Excel workbook&amp;nbsp;password. You could use this add-in as Excel password manager too. For example if you using many passwords for many files - this add-in will help you to open these files quickly.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://sites.google.com/site/xedocfiles/files/dictattack.zip&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Download Add-In&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
How to use: &lt;br /&gt;
1. Open dictattack.xla&lt;br /&gt;
2. Find new Utilities option in main menu. In Excel 2007 it will be located under Add-Ins menu.&lt;br /&gt;
3. Use Utilities-&amp;gt;Add password(s) to dictionary to manage your passwords list. You have few options to add new passwords: press Show Dictionary button and copy/paste a list to any place you like, Load dictionary from .txt file (one password per line) or enter password into New password field and push Add:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRaykPkhYjVJQIwYu_ccOODlzEj30bMbNuR7ZCw8ApU7A_QyR4kyutVigpmnaFL1SUx2rI01bZb2b2PVJsv3xyYw9Td-0bEZV25TDOzkafX9C-cpjLE-dO7ml4HYI4SLW8fu1WgbPxK-A/s1600-h/dictionarypassword.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; mt=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRaykPkhYjVJQIwYu_ccOODlzEj30bMbNuR7ZCw8ApU7A_QyR4kyutVigpmnaFL1SUx2rI01bZb2b2PVJsv3xyYw9Td-0bEZV25TDOzkafX9C-cpjLE-dO7ml4HYI4SLW8fu1WgbPxK-A/s320/dictionarypassword.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;4. Use Utilities-&amp;gt;Open protected files to open password protected file(s). You will get a message if some files could not be opened.&lt;br /&gt;
&lt;br /&gt;
Have fun!</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/1230836252313236663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-dictionary-password-attack-macro.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/1230836252313236663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/1230836252313236663'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-dictionary-password-attack-macro.html' title='Excel Dictionary Password Attack macro'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRaykPkhYjVJQIwYu_ccOODlzEj30bMbNuR7ZCw8ApU7A_QyR4kyutVigpmnaFL1SUx2rI01bZb2b2PVJsv3xyYw9Td-0bEZV25TDOzkafX9C-cpjLE-dO7ml4HYI4SLW8fu1WgbPxK-A/s72-c/dictionarypassword.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-9202868973131817322</id><published>2010-01-22T18:56:00.003+02:00</published><updated>2010-01-22T22:49:33.460+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel macro sum count countblank automatic"/><title type='text'>Excel macro. Multiple range formula quick input</title><content type='html'>Sometime you need to build a formula which should refer to many sheets and many ranges. Like =SUM(Sheet1!E:K;Sheet2!A:B;Sheet3!D:C)&lt;br /&gt;
To do this you need to type =SUM( then select sheet, select range, type ;, select n-th sheet again, select range.... Yeah thats boring ! &lt;br /&gt;
I wrote an Excel Add-In to automate this task partialy:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;http://sites.google.com/site/xedocfiles/files/rangeformula.zip&quot;&gt;Download Add-In&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
What you need to do:&lt;br /&gt;
1. Place rangeformula.xla somewhere in My Documents and install it with double-click.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7J3SpFJWdfxSS6HIY-w9S7kjV8wawfERXQBOGRXKVbVz4glZh0M0y5L6wKMjf7UBjqUBb3v5g0vg1z0Xnuq5fZ2qP0zbmBYKeXqNROxUCp4jw4WdESBXKj7zyfIXQOqDSI870upToqwI/s1600-h/excelrangeformula.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7J3SpFJWdfxSS6HIY-w9S7kjV8wawfERXQBOGRXKVbVz4glZh0M0y5L6wKMjf7UBjqUBb3v5g0vg1z0Xnuq5fZ2qP0zbmBYKeXqNROxUCp4jw4WdESBXKj7zyfIXQOqDSI870upToqwI/s320/excelrangeformula.jpg&quot; width=&quot;283&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
2. Switch between sheets and select ranges you want to include to formula. Selection will be saved per sheet.&lt;br /&gt;
3. In Excel 97/2k/2k3 use menu Utilities-&amp;gt;Range Formula to open input form of add-in (look picture). In Excel 2007 Utilities submenu will be installed under Add-Ins menu.&lt;br /&gt;
4. Enter Function name e.g. SUM or COUNTBLANK without brackets and equal sign&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Select ranges in list which you want to include into formula&lt;br /&gt;
6. Copy/Paste Result formula. &lt;br /&gt;
&lt;br /&gt;
Have fun !</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/9202868973131817322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-macro-multiple-range-formula.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/9202868973131817322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/9202868973131817322'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-macro-multiple-range-formula.html' title='Excel macro. Multiple range formula quick input'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7J3SpFJWdfxSS6HIY-w9S7kjV8wawfERXQBOGRXKVbVz4glZh0M0y5L6wKMjf7UBjqUBb3v5g0vg1z0Xnuq5fZ2qP0zbmBYKeXqNROxUCp4jw4WdESBXKj7zyfIXQOqDSI870upToqwI/s72-c/excelrangeformula.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-3878159452362829334</id><published>2010-01-21T15:47:00.011+02:00</published><updated>2013-07-11T17:40:02.064+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel password remover crack forgotten reset free freeware"/><title type='text'>Excel password crack. Recover your forgotten password for free.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
There is simple way to recover forgotten Excel password using Excel itself. I wrote a small VBA addin for this purpose. You can use it for free to recover your forgotten Excel password.&lt;br /&gt;
But if you like it, please consider making a donation.&lt;br /&gt;
Source code is open so you could see how it works. Here is link for addin download:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;a href=&quot;http://sites.google.com/site/xedocfiles/files/password_crack.xla&quot;&gt;Download Add-In&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The idea is to iterate fake passwords (up to 8 characters) where first 1-8 characters are &quot;A&quot; or &quot;B&quot; and last one have code from 32 to 255. &lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;This utility works with Excel 97/2000/2003 only.&amp;nbsp; Excel 2007 have stronger protection and this method doesn&#39;t work there.  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Here is source code&lt;/span&gt; with comments:&lt;/div&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Const MENUNAME = &quot;UNPROTECT&quot;
Sub test()
On Error Resume Next
    Dim wb As Workbook
    Const LastCharStart = 32
    Const LastCharFinish = 255
    For i = 1 To 255
        fakepassword = FakePass(i)
        For LastCharIndex = LastCharStart To LastCharFinish
            Password = fakepassword &amp;amp; Chr(LastCharIndex)
            Set wb = Workbooks.Open(&quot;trypass.xls&quot;, , , , Password)
            Debug.Print Password
            If Not wb Is Nothing Then: Exit For
        Next
    Next
End Sub
&#39;Install menu shortcut
Sub Auto_Open()
    Install
End Sub

&#39;Crack Worksheets and Workbooks passwords at once
Sub BruteForceUnprotect()
    Dim ProtectedObjects As New Collection
    Const LastCharStart = 32
    Const LastCharFinish = 255
    
    Application.DisplayAlerts = False
    
    If Workbooks.Count &amp;lt;= 0 Then
        MsgBox &quot;Open some workbook first!&quot;
        Exit Sub
    End If
    
    
    &#39;Add protected Workbooks to collection
    If (ActiveWorkbook.ProtectStructure Or ActiveWorkbook.ProtectWindows) Then
        ProtectedObjects.Add ActiveWorkbook
    End If
    
    &#39;Add protected Worksheets to collection
    On Error Resume Next
    &#39;Dim WSheet As Worksheet
    For Each WSheet In ActiveWorkbook.Worksheets
        WSheet.Protect (&quot;&quot;)
        If Not WSheet.Unprotect(&quot;&quot;) Then: ProtectedObjects.Add WSheet
    Next
    On Error GoTo 0
    
    If ProtectedObjects.Count &amp;lt;= 0 Then
        MsgBox &quot;No protected objects or password is empty!&quot;
        Exit Sub
    End If
    
    &#39;Brute force with fake password. Original password could not be restored in this way.
    For i = 1 To 255
        fakepassword = FakePass(i)
        If ProtectedObjects.Count = 0 Then: Exit For
        For LastCharIndex = LastCharStart To LastCharFinish
            Password = fakepassword &amp;amp; Chr(LastCharIndex)
            If ProtectedObjects.Count &amp;gt; 0 Then
                For j = 1 To ProtectedObjects.Count
                    If UnprotectObject(ProtectedObjects(j), Password) = True Then
                        ProtectedObjects.Remove (j)
                        If ProtectedObjects.Count &amp;gt; 0 Then: j = j - 1
                    End If
                Next
            End If
        Next
    Next
    
    If ProtectedObjects.Count = 0 Then
        MsgBox &quot;Workbook and Worksheets passwords was removed!&quot;
    Else
        MsgBox &quot;Non standard encryption detected :(. Some objects are still protected.&quot;
    End If
    Application.DisplayAlerts = True
End Sub
Function UnprotectObject(obj, pass)
  UnprotectObject = False
  On Error GoTo WrongPassword
  obj.Unprotect pass
  UnprotectObject = True
WrongPassword:
End Function
&#39;Build password by given numeric value.
Function FakePass(Value)
    Mask = 1
    FakePass = &quot;&quot;
    While Mask &amp;lt;= Value
        If (Value And Mask) = 0 Then
            FakePass = &quot;A&quot; &amp;amp; FakePass
        Else
            FakePass = &quot;B&quot; &amp;amp; FakePass
        End If
        Mask = Mask * 2
    Wend
    If Len(FakePass) &amp;gt; 0 Then: FakePass = Right(FakePass, Len(FakePass) - 1)
End Function
&#39;Install menu shortcut
Sub Install()
    Uninstall True
    AddButton MENUNAME, &quot;Unprotect everything&quot;, &quot;BruteForceUnprotect&quot;
    AddButton MENUNAME, &quot;Uninstall addon&quot;, &quot;Uninstall&quot;
End Sub
&#39;Uninstall menu shortcut
Sub Uninstall(Optional silent = False)
    If Not silent Then
        If MsgBox(&quot;Do you really want to uninstall this addon ?&quot;, vbYesNo) = vbNo Then
            Exit Sub
        End If
    End If
    On Error Resume Next
    Application.CommandBars(&quot;Worksheet Menu Bar&quot;).Controls(MENUNAME).Delete
    On Error GoTo 0
End Sub
&#39;Add menu item
Sub AddButton(menu As String, submenu As String, macro As String, Optional descr As String = &quot;&quot;)
    On Error GoTo createmenu
    If IsNull(Application.CommandBars(&quot;Worksheet Menu Bar&quot;).Controls(menu)) Then: GoTo createmenu
    On Error GoTo create
    If IsNull(Application.CommandBars(&quot;Worksheet Menu Bar&quot;).Controls(menu).Controls(submenu)) Then: GoTo create
    End
createmenu:
    Set mnu = Application.CommandBars(&quot;Worksheet Menu Bar&quot;).Controls.Add(Type:=10)
    mnu.Caption = &quot;&amp;amp;&quot; &amp;amp; menu
    mnu.Visible = True
    
create:
    Set Button = Application.CommandBars(&quot;Worksheet Menu Bar&quot;).Controls(menu).Controls.Add(Type:=1, ID:=2950)
    With Button
        .DescriptionText = descr
        .TooltipText = descr
        .Caption = &quot;&amp;amp;&quot; &amp;amp; submenu
        .Style = 3
        .OnAction = macro
    End With
End Sub


&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/3878159452362829334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-password-crack.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/3878159452362829334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/3878159452362829334'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-password-crack.html' title='Excel password crack. Recover your forgotten password for free.'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-5287666978184296489</id><published>2010-01-20T13:07:00.010+02:00</published><updated>2010-01-20T17:07:50.879+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="word password crack remove reset freeware free"/><title type='text'>Crack Microsoft Word password</title><content type='html'>It is possible to remove read-only password protection of Word document using MS Word itself. You don&#39;t need any software excepting Word to do this.&lt;br /&gt;
&lt;br /&gt;
Follow these steps to unprotect your document:&lt;br /&gt;
1. Open document&lt;br /&gt;
2. Press Alt+Shift+F11. Microsoft Script Editor will be opened.&lt;br /&gt;
3. Press Ctrl+F and type &quot;pass&quot; (without quotes) in the Find what field.&lt;br /&gt;
&lt;table style=&quot;width: auto;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://picasaweb.google.com/lh/photo/etXav9tNwwHoSuWlHgN8Nw?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuI2IXwJZqe6aV_kPYw9t0mixm3VfWouqQXkfC6wP93Q5WKxF7qljraqm2QHD1_qjh2x9f59BXBpZPAPxg4kWgvQZTIXjywtfa4POx00o5f_OuTrxjj4KemOm_YAl1SMmUWYNS4UVVuGM/s288/Find%20Word%20password.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;4. Press Find Next. You will find the line like: &amp;lt;w:UnprotectPassword&amp;gt;1234F8E7&amp;lt;/w:UnprotectPassword&amp;gt;&lt;br /&gt;
&lt;table style=&quot;width: auto;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;http://picasaweb.google.com/lh/photo/EsjVb4EEDOEjiDPaUfaVmA?feat=embedwebsite&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLUBqwKVUKw8-4dAAQW5BnlzF3-7DMqg5bOu6KTNmVSv9L6Q7-ZXoRdkfKELH6EQFnNfUcU6o8umzw5Ur6ctl2MgE2kgk9dOD92EDg5-rc7lj8g0SeOMQRz16vARn2LCsbfC2OTtHgiCE/s288/Word%20script%20editor%20password.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;5. Select whole line and delete it&lt;br /&gt;
6. Press Ctrl+S to save document&lt;br /&gt;
7. Close Microsoft Script Editor&lt;br /&gt;
8. Go to Tools-&amp;gt;Unprotect document. This will reset read-only password protection.</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/5287666978184296489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/reset-microsoft-word-password.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/5287666978184296489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/5287666978184296489'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/reset-microsoft-word-password.html' title='Crack Microsoft Word password'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuI2IXwJZqe6aV_kPYw9t0mixm3VfWouqQXkfC6wP93Q5WKxF7qljraqm2QHD1_qjh2x9f59BXBpZPAPxg4kWgvQZTIXjywtfa4POx00o5f_OuTrxjj4KemOm_YAl1SMmUWYNS4UVVuGM/s72-c/Find%20Word%20password.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-338842517363861534</id><published>2010-01-20T12:40:00.003+02:00</published><updated>2010-01-20T13:15:53.396+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel vba speed up"/><title type='text'>Excel VBA speed up</title><content type='html'>&lt;span style=&quot;font-weight: bold;&quot;&gt;1. Speed up Excel cells reading/writing using Range.Resize()&lt;/span&gt;&lt;br /&gt;
There two ways to read Excel cells programatically. First method is to use loops. This method is simple and ... slow. &lt;br /&gt;
Here is sample code:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;For i = 1 To 10
  destination.Cells(i,1).value = source.Cells(i,1).value 
Next
&lt;/pre&gt;As you see there was 10 reads and 10 writes in loop. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;You can use Resize() method of Range class to speed up cells reading and writing..&lt;/span&gt; Resize method allows to read range of cells at once.&lt;br /&gt;
&lt;br /&gt;
Sample code:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Dim arSales as Variant
arSales = source.Cells.Resize(10,1)
&lt;/pre&gt;&lt;br /&gt;
This method reads specified range to array almost instantly. In Excel 2003 you can get entire sheet (65536x256 cells) in seconds.&lt;br /&gt;
You can write data to Excel sheet in same way using prepared array.&lt;br /&gt;
&lt;br /&gt;
Sample code:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;destination.Cells.Resize(10,1) = arSales
&lt;/pre&gt;&lt;br /&gt;
In some cases you don&#39;t need to use Resize to get array of cells. Use Value property of Range if you want to get all Cells of range.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Set rng = Range(&quot;DATA&quot;)
arSales = rng.Value
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;2. Disable automatic calculation, screen update and events&lt;/span&gt;&lt;br /&gt;
Each change of worksheet invokes automatic calculation of entire workbook. This behavior is useful when you do some manual input but unacceptable for VBA methods.&lt;br /&gt;
You can use Application properties to disable unnecessary updates.&lt;br /&gt;
&lt;br /&gt;
Sample code:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
&lt;/pre&gt;&lt;br /&gt;
And to return settings back :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;3. Conditional formatting&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Sometime we need to format Excel sheet using VBA. MS Excel provides few ways to do this with VBA.&lt;br /&gt;
First one is to use Color and Font properties of Range class.&lt;br /&gt;
&lt;br /&gt;
Sample code:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Set rng = Range(&quot;HEADER&quot;)
    With rng.Interior
        .ColorIndex = 6
        .Pattern = xlSolid
    End With
    With rng.Font
        .Font.Italic = True
        .Font.Bold = True
        .Name = &quot;Arial&quot;
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
&lt;/pre&gt;&lt;br /&gt;
This code works well but it have few disadvantages. It is slow when complex formatting required and incredibly hard to tune it later. &lt;br /&gt;
&lt;br /&gt;
Second method is Conditional formatting usage. The idea is to format cells automatically if they contain some data. &lt;br /&gt;
1. Create Excel file with header and other static information;&lt;br /&gt;
2. Apply Conditional formatting to first row of range where data will be placed. Select font/colors and use condition like if A2&lt;&gt;&quot;&quot;;&lt;br /&gt;
3. Place data into A2 cell using VBA. This will fire automatic formatting.&lt;br /&gt;
&lt;br /&gt;
Benefits of this method is speed and flexibility. Color and font picker simplifies formatting and code.&lt;br /&gt;
&lt;br /&gt;
Sample code:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;rowscount = 20000 &#39; Rows number to format
colscount= 5   &#39; Columns number to format
onepass = 1024 &#39; Rows number to format at once
src_row = 1    &#39; Row number where conditional format is set
For i = src_row+1 To rowscount Step onepass
  Rows(src_row).Resize(1, colscount).Copy &#39; Copy row format
  If i + onepass &amp;gt; rowscount Then: onepass = rowscount - i
  &#39; Paste format
  Rows(i).Resize(onepass, colscount).PasteSpecial _  
    Paste:=xlPasteFormats, _
    Operation:=xlNone, _
    SkipBlanks:=False, _ 
    Transpose:=False
Next
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/338842517363861534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-vba-speed-up.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/338842517363861534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/338842517363861534'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/excel-vba-speed-up.html' title='Excel VBA speed up'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5768677426437492644.post-3770300441300053915</id><published>2010-01-19T10:09:00.000+02:00</published><updated>2010-01-19T10:09:28.158+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="vba excel last cell"/><title type='text'>Last cell in range</title><content type='html'>To get last cell in ActiveSheet you can use this code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Set LastCell = ActiveSheet.SpecialCells(xlLastCell)
&lt;/pre&gt;&lt;br /&gt;
This code works in most cases. But you could face a problem when data was inserted and deleted at the end of sheet. As an example if you clear 5 of 10 filled rows on the sheet, SpecialCells(xlLastCell) will not be changed. It will point to 10th row instead of 5th.&lt;br /&gt;
To get last cell of non-empty row you need to use this code:&lt;br /&gt;
&lt;br /&gt;
Sample:&lt;br /&gt;
&lt;pre class=&quot;vb&quot; name=&quot;code&quot;&gt;Set LastCell = ActiveSheet.UsedRange.SpecialCells(xlLastCell)
&lt;/pre&gt;&lt;br /&gt;
Worksheet.UsedRange is object of Range class which contains filled cells only.</content><link rel='replies' type='application/atom+xml' href='http://vbacodesamples.blogspot.com/feeds/3770300441300053915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/last-cell-in-range.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/3770300441300053915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5768677426437492644/posts/default/3770300441300053915'/><link rel='alternate' type='text/html' href='http://vbacodesamples.blogspot.com/2010/01/last-cell-in-range.html' title='Last cell in range'/><author><name>xedoc</name><uri>http://www.blogger.com/profile/04461259729025237418</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>