Monday, August 29, 2011

Adding macros in a Word document on the fly

This one was troubeling me for AGES! I heard people saying it can't be done. But i knew deep down i could do it. But alas, a few things were missing. I could add the code as a module but not in the ThisDocument. I was getting depresed. What was the solution??? WHAT?

Well it was very simple! This line gave me the answer:
vbc = oDoc.VBProject.VBComponents(0)

where 0 is the ThisDocument with 1 the first module Module1! I was so happy! And to help all the other people with similar problems, i include the code i used. Hope this helps. (The code is not cleared up, needs a SaveAs command to save the document you just edited).

Also i would like to thank rxbagain from www.codeGuru.com that pointed me to the right direction. Thank you.

' ==========================================================================

Dim strFilenameToConvert As String
Dim procLine As Long
Dim oDoc As New Microsoft.Office.Interop.Word.Document
Dim vbProj As Microsoft.Vbe.Interop.VBProject
Dim vbc As Microsoft.Vbe.Interop.VBComponent
Dim vbcode As Microsoft.Vbe.Interop.CodeModule
Dim wordApp = New Microsoft.Office.Interop.Word.Application
Dim oModule As VBIDE.VBComponent

wordApp.Application.DisplayAlerts = False
strFilenameToConvert = "C:\hello.docx"
wordApp.WindowState = Word.WdWindowState.wdWindowStateNormal
wordApp.Visible = True
oDoc = wordApp.Documents.Open(strFilenameToConvert)

vbProj = oDoc.VBProject
vbc = oDoc.VBProject.VBComponents(0)
vbcode = vbc.CodeModule

' check if the procedure is already there
On Error Resume Next
procLine = vbcode.ProcBodyLine("Document_Open", vbext_ProcKind.vbext_pk_Proc)
On Error GoTo 0
' and add only if not found
If procLine = 0 Then
vbcode.AddFromString( _
"Private Sub Document_Open()" & vbCrLf & _
" MsgBox " & Chr(34) & "Macro added programmatically" & Chr(34) & vbCrLf & _
"End Sub")
End If

vbcode = Nothing
vbc = Nothing
vbProj = Nothing
oDoc = Nothing

Friday, May 20, 2011

My life with a Samsung Galaxy S model I9000

I am lucky enough, and unlucky too, to have one of the 2010 flagship models of Samsung; the now famous Galaxy S I9000 model. I was testing it for over 2 months with continuous tweaking and changing things around.

The model came with the 2.1 version of the Android OS. And let me tell you it sucked BIG TIME! Don’t get me wrong the hardware is not bad at all, visit http://www.gsmarena.com/samsung_i9000_galaxy_s-3115.php for more information on the specs, the biggest problem that I had was the software.

Yes the software was so bad that made the phone unusable. What can I point out? The loss of WiFi signal after coming out of hibernation? The legendary lag? The unresponsive buttons? The mysterious beeps and buzzes after pressing the home button that resulted in a phone reset? The KIES? The inability to connect to exchange server without a Google account? The need to reset the phone to the factory defaults every couple of days when emails were stuck on the out tray in the inbuilt Exchange email connection? The GPS taking 10 minutes to find a satellite in an EMPTY lot of land with CLEAR SKY in a capital city?

The things that I have seen the past months still make my head spin. Let’s face it the version 2.1 was sucky! No doubt about it!

And then....then...version 2.2 came out. With a MAJOR DELAY. And none of the problems got fixed. Some minor improvements, but nothing major. I still had all the previous errors. Yes the connection to the Exchange server worked better, well, sort of....

At that time I really hated the Android. Don’t know if it was Samsung’s fault, the Android’s developers fault, or both, but my life was getting more stressful when I had users complaining about the phone and wanting a solution.

One day I had enough. I couldn’t take it no more. I really like Android OS, in comparison with the Apple iOS, but this was ridiculous! How am I supposed to use a broken-down OS for work? No Microsoft jokes please! I saw you back there smirking!
I started looking around the net for some sort of solution and relief to my misery. I saw several posts about a leaked version of the next update, 2.3.2 or something, and some instructions how to install it into your phone using the ODIN software.

I said, “what the heck, I’ll try it”, and soon enough I was downloading the files necessary for the upgrade. Nervously I followed the instructions in how to use ODIN (very easy to be honest) and after about 10-20 minutes of highly stressful time, my phone reset itself to the new Android OS.

And I felt such a delight! My phone, was....actually.....working! As it should! GPS connected in 1 minute outside a building. Exchange was working without a Gmail account needed. No more emails stuck on out tray. Lag disappeared! COMPLETELY! WiFi wasn’t loosing connection coming out of hibernation. Not even once! Battery life seemed better, well just a bit. I was saved!! SAVED!

Without delay I upgraded more phones, in (believe it or not) worst situation than mine. And those were saved too! Now I’m not sure when the new official release comes out if the KIES software will be able to upgrade this “custom” build, but that’s something for the future for me to worry about right now. (Oh by the way, download KIES AIR from the Samsung AppStore. It’s WAAAAAAY better than the KIES that you install on your computer. You can see even the messages that you sent or received. Give it a try)

I can’t understand why Samsung hasn’t issue the new update yet. Yes we still wait for the official release of the software. Samsung is notorious for breaking deadlines all the time. I wonder how’s their Quality Assurance department sleeps at night? Or there isn’t one?

Thanks to the people that leaked the “unofficial-official” release I have a phone that works and performs as I want it to perform. If you have the same problems download ODIN and the necessary files and give it a go. You will be amazed.