Consulting

Results 1 to 2 of 2

Thread: "Compile error: Method or data member not found" assistance

  1. #1
    VBAX Regular
    Joined
    Mar 2014
    Posts
    18
    Location

    "Compile error: Method or data member not found" assistance

    As the title states I get a compile error on
    NewWB.TopMargin = 0.3
    ".TopMargin =" is highlighted in blue as shown above when the error message is displayed. All I am trying to do is open workbook file located on a server and copy and paste it in another worksheet in another workbook and set the page setup the margin values where the worksheet is to be pasted to. Here is the full code below.

    Option ExplicitPrivate Sub Workbook_Open()
            
            
            Dim sPath As String, sFile As String
            Dim wb As Workbook
            
            sPath = "Z:\GRP\EVERYONE\FORMS\"
            sFile = sPath & "F-103-04 Exh I-Solid Dose Usage Record-Rev001.xlsx"
            Set wb = Workbooks.Open(sFile)
            Call OpenSDUsageRecord
    Sub OpenSDUsageRecord()    
        Dim NewWB As Worksheet
        
        Set NewWB = Application.Workbooks("ChattemPackaging.xlsm").Worksheets("Solid Dose Usage Record")
        ActiveWorkbook.Copy NewWB
        
            NewWB.TopMargin = 0.3
            NewWB.LeftMargin = 0.2
            NewWB.BottomMargin = 0.3
            NewWB.FooterMargin = 0.2
            NewWB.RightMargin = 0.2
            NewWB.HeaderMargin = 0.2
    End Sub
    Thank You

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    .TopMargin is a property of .PageSetup which is a property of Worksheet, not the workbook

    The VBE object browser (F2) is helpful for this things

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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