Results 1 to 13 of 13

need page break by asking the input file for page break to be done

Threaded View

saikumar need page break by asking the... 12-10-2008, 12:04 AM
royUK Why are you creating a new... 12-10-2008, 04:59 AM
saikumar I thought that way i can... 12-10-2008, 05:59 AM
royUK Try the code that I posted 12-10-2008, 06:10 AM
saikumar where is the code ? i think... 12-10-2008, 06:23 AM
royUK I edited your code & posted... 12-10-2008, 06:27 AM
saikumar Hi roy, I have pasted the... 12-10-2008, 06:43 AM
royUK Try this Option... 12-10-2008, 06:55 AM
saikumar Welcome. But heading is... 12-10-2008, 07:03 AM
royUK The code does not affect that... 12-10-2008, 07:27 AM
saikumar Thanks it works fine. 12-10-2008, 07:33 AM
  1. #1
    Registered User
    Join Date
    12-03-2008
    Location
    chennai
    Posts
    62

    need page break by asking the input file for page break to be done

    I need some more help from you.

    The code which you provided works fine no problem for a page break. I need to run the macro for the page break by asking the input file for page break to be done.

    For Example, If excel filename "A" contain the code which you have given need to ask to input the filename "B" and process need to be done in file "B".

    I have added some code to your code which you provided but it gives error message "1004" "Method 'Range' of object '_Application' failed" at following line :

    Set rng = oExcel.Range(Cells(2, 2), Cells(Rows.Count, 2).End(xlUp))

       Option Explicit
       Dim V_fileloc As String
       Dim oExcel As Excel.Application
       Dim oWB As New Workbook
    Sub addPageBreak()
        Dim rng    As Range
        Dim cl     As Range
    
        V_fileloc = ""
    
        V_fileloc = Application.GetOpenFilename("Page Break File (*.xls),*.xls", , "Page Break File")
    
        If (V_fileloc = "" Or V_fileloc = "False") Then
            MsgBox "Page Break File, Should be selected", vbApplicationModal, "Files"
            Exit Sub
        End If
    
        Set oExcel = CreateObject("excel.Application")
        Set oWB = oExcel.Workbooks.Open(V_fileloc)
        oExcel.Worksheets("Sheet1").Activate
        oExcel.Sheets("Sheet1").Select
     
        Set rng = oExcel.Range(Cells(2, 2), Cells(Rows.Count, 2).End(xlUp))
        On Error Resume Next
        oExcel.ResetAllPageBreaks
        oExcel.PageSetup.PrintArea = ""
        For Each cl In rng
            If cl.Value <> cl.Offset(1, 0).Value Then
                oExcel.HPageBreaks.Add Before:=cl.Offset(1, 0)
            End If
        Next cl
        
        oWB.Close
        Set oWB = Nothing
               
        oExcel.Quit
        Set oExcel = Nothing
    
        On Error GoTo 0
    End Sub
    Last edited by saikumar; 12-10-2008 at 07:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1