Thursday 13 February 2014

VBA function to convert column number to letter?


Function Col_Letter(lngCol As Long) As String

Dim vArr
vArr = Split(Cells(1, lngCol).Address(True, False), "$")
Col_Letter = vArr(0)
End Function

Sub Test()
MsgBox Col_Letter(100)
End Sub

Friday 7 February 2014

AllowFormattingCells Property [Excel 2003 VBA Language Reference]

Sub ProtectionOptions()

    ActiveSheet.Unprotect

    ' Allow cells to be formatted on a protected worksheet.
    If ActiveSheet.Protection.AllowFormattingCells = False Then
        ActiveSheet.Protect AllowFormattingCells:=True
    End If

    MsgBox "Cells can be formatted on this protected worksheet."

End Sub

How to write the string(unicode) to textfile

Set fs = CreateObject("Scripting.FileSystemObject")

dlgSaveAsString = Application.GetSaveAsFilename("ABCD.txt", FileFilter:="text file (*.txt),*.txt")

If (dlgSaveAsString <> False) Then
    Set a = fs.CreateTextFile(dlgSaveAsString, True, True)
    a.writeline (kmlText)
    a.Close
End If

for more details: please check the below text and link

CreateTextFile Method
See Also    Example    Applies To    Specifics
Description
Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.
Syntax
object.CreateTextFile(filename[, overwrite[, unicode]])
The CreateTextFile method has these parts:

Part
Description
object
Required. Always the name of a FileSystemObject or Folder object.
filename
Required. String expression that identifies the file to create.
overwrite
Optional. Boolean value that indicates if an existing file can be overwritten. The value is True if the file can be overwritten; False if it can't be overwritten. If omitted, existing files are not overwritten.
unicode
Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is True if the file is created as a Unicode file; False if it's created as an ASCII file. If omitted, an ASCII file is assumed.


http://msdn.microsoft.com/en-us/library/aa265018(v=vs.60).aspx