write at exceltoexplore@gmail.com : Report Automation|Dashboard in Excel| Provide Excel consulting through macro (VBA) automation |Financial Modeling | Ethical Hacking

Tuesday, 31 January 2012

Excel : Create PDF from excel worksheet

you can use below code  for Excel to PDF conversion


Sub CreatePDF()
    Dim wksSheet As Worksheet
    Dim blnFlag As Boolean
    Dim intI As Integer
    Dim intResult As Byte
 
    intI = 0
    intResult = Application.InputBox("Type 1 for Entire Workbook and Type 0 For Active Worksheets")
    If intResult = 0 Then
    Set wksSheet = ActiveSheet
            wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                    ThisWorkbook.Path & "\" & wksSheet.Name, Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
                    False
            Exit Sub
    End If
    For Each wksSheet In ThisWorkbook.Worksheets
        If WorksheetFunction.CountA(wksSheet.Cells) <> 0 Then
            If wksSheet.Visible = xlSheetHidden Then
                wksSheet.Visible = xlSheetVisible
                blnFlag = True
            End If
            wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                    ThisWorkbook.Path & "\" & wksSheet.Name, Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
                    False
                    intI = intI + 1
            If blnFlag = True Then
            wksSheet.Visible = xlSheetHidden
            blnFlag = False
            End If
        End If
    Next
    MsgBox intI & " Worksheet(s) has been Exported to PDF", vbInformation
   End Sub

Saturday, 21 January 2012

Excel : Hack/download Greetings (swf file) from web & Embedding in excel

I found this is best way to wish your friend on any occasion
Most company block certain web sites so even you send them E Greeting card they may not able to view

Hack/download Greetings (swf file ) from http://www.123greetings.com/
1. Go to url http://www.123greetings.com/
2. click on the e card which you want to download

3. Press Ctrl + U or Right click on web page & select view page source
4. Press Ctrl + F & find swf
5. find the url of swf file as shown in below image

4.  Copy the url to new browser window
5.  Press ctrl + S
6. Save the web page. it will save the file in swf ( Shockwave Flash Object ) format
7. Further you can convert this file to any video format using software
  http://www.dvdvideosoft.com/products/
8. You can insert this file in excel as well
 http://excelvbaandmacros.blogspot.com/2011/12/excel-why-this-kolaveri-diembed.html

Wednesday, 11 January 2012

Excel : Delete Blank Rows & Column from worksheet

Try Below :


Sub DeleteBlankRows()
    Dim Rw As Long, RwCnt As Long, Rng As Range
   
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
   
On Error GoTo Exits:
   
    If Selection.Rows.Count > 1 Then
        Set Rng = Selection
    Else
        'Set Rng = Range("A1:B6")
     Set Rng = Range(Rows(1), Rows(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row()))
    End If
    RwCnt = 0
    For Rw = Rng.Rows.Count To 1 Step -1
        If Application.WorksheetFunction.CountA(Rng.Rows(Rw).EntireRow) = 0 Then
            Rng.Rows(Rw).EntireRow.Delete
            RwCnt = RwCnt + 1
        End If
    Next Rw
   
Exits:
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
   
End Sub

Sub DeleteBlankColumns()
    Dim Col As Long, ColCnt As Long, Rng As Range
   
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
   
On Error GoTo Exits:
   
    If Selection.Columns.Count > 1 Then
        Set Rng = Selection
    Else
    'Set Rng = Range("A1:B6")
        Set Rng = Range(Columns(1), Columns(ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column()))
    End If
    ColCnt = 0
    For Col = Rng.Columns.Count To 1 Step -1
        If Application.WorksheetFunction.CountA(Rng.Columns(Col).EntireColumn) = 0 Then
            Rng.Columns(Col).EntireColumn.Delete
            ColCnt = ColCnt + 1
        End If
    Next Col
   
Exits:
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
   
End Sub

Sunday, 8 January 2012

Excel : Export Userform to another workbook

User below code to Export User Form from one workbook to another


Sub Mtest()
    Dim wbSource As Workbook, wbDestination As Workbook
    Set wbSource = Workbooks("Book1")
    Set wbDestination = Workbooks("Book2")
    wbSource.VBProject.VBComponents("Userform1").Export "C:\temp\Userform1.frm"
    wbDestination.VBProject.VBComponents.Import "C:\temp\userform1.frm"

    Kill "C:\temp\userform1.frm"
    Kill "C:\temp\userform1.frx"

End Sub