Results 1 to 29 of 29

run time error 91 problem

Threaded View

stevesunfold run time error 91 problem 10-21-2008, 01:04 PM
Leith Ross Hello stevesunfold, The... 10-21-2008, 03:50 PM
stevesunfold hi leith and thanks for the... 10-22-2008, 12:32 PM
jasoncw From where is the varaible... 10-22-2008, 12:48 PM
stevesunfold hi jason im not sure what you... 10-22-2008, 12:51 PM
Leith Ross Hello stevesunfold, Can... 10-22-2008, 01:12 PM
stevesunfold no problem leith cell b69... 10-22-2008, 01:19 PM
  1. #1
    Forum Contributor
    Join Date
    06-23-2007
    Posts
    690

    run time error 91 problem

    hi gents
    just a small issue

    i have this fantastic piece of code by protonleah which works
    Sub COPYandPRINT()
         Application.ScreenUpdating = False
         Application.DisplayAlerts = False
         ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=False
         
         PORow = PONUMBER.Value + 1
         
         Sheets("PURCHASE ORDER NUMBERS").Range("A" & PORow).Value = PONUMBER
         Sheets("PURCHASE ORDER NUMBERS").Range("B" & PORow).Value = SUPPLIER
         Sheets("PURCHASE ORDER NUMBERS").Range("C" & PORow).Value = xDATE
         Sheets("PURCHASE ORDER NUMBERS").Range("D" & PORow).Value = JOBNUMBER
         Sheets("PURCHASE ORDER NUMBERS").Range("E" & PORow).Value = CUSTOMERNAME
         Sheets("PURCHASE ORDER NUMBERS").Range("F" & PORow).Value = DESCRIPTION
         Sheets("purchase order").Select
         
         Range("B16:F19,K17:L20,B23:C24,G23:H24,I23:K24,B28:L57").Select
         Range("B16").Activate
         Selection.ClearContents
         Application.ScreenUpdating = True
         PONUMBER = PONUMBER + 1
         Range("B16").Select
         Application.DisplayAlerts = False
    End Sub
    this works perfectly

    i then try to add my save to specific folder code and i get an error

    Sub SaveJobFile()
    'declare all variables
    Dim stOfPath As String
    Dim ActualMidFolder As String
    Dim EndOfNameAndPath As String
    Dim FileNameToSave As String
    Dim JobNum As String
    Dim PONum As String
    Dim SuppliersName As String
    
    'define initial variables (note: the ranges may need to be changed
        JobNum = Range("G23").Value
        PONum = Range("k12").Value
        SuppliersName = Range("b16")
        EndOfNameAndPath = SuppliersName & " Purchase Order " & PONum & Format(Date, " dd.mm.yy") & ".xls"
    
    'test to see if it is stock or PO (?) & define the saving path accordingly
        Select Case UCase(Left(JobNum, 1)) = "J"
            Case True
    'Rob's test path:     stOfPath = "C:\Documents and Settings\HP_Owner\My Documents\"
                stOfPath = Range("B69") & "\"
                'test for any likely folders
                    If Not (DoesFileFolderExist(stOfPath & JobNum & "*")) Then GoTo TheEnd
                'identify the exact folder
                    ActualMidFolder = GetActualFolderName(stOfPath, JobNum) & "\"
                'define rest of file name
                    EndOfNameAndPath = "Docs\" & EndOfNameAndPath
                    FileNameToSave = stOfPath & ActualMidFolder & EndOfNameAndPath
            Case False
                stOfPath = Range("B70") & "\"
                If Not (DoesFileFolderExist(stOfPath)) Then GoTo TheEnd
                    FileNameToSave = stOfPath & EndOfNameAndPath
        End Select
    
    'save the file & finish macro
        ActiveWorkbook.SaveAs Filename:=FileNameToSave
        Exit Sub
    
    TheEnd:
    'warn nothing exists & end the macro
        MsgBox "Macro ending b/c no Folder with the following number exists : " & stOfPath & JobNum & "*", , "FYI"
        Debug.Print stOfPath & JobNum & "*"
    End Sub
    
    Public Function DoesFileFolderExist(strfullpath As String) As Boolean
    'sourced from www.excelguru.ca/node/30 by Ken Puls
    'note it only checks for the existence of the lowest folder (or the file) in the strfullpath string.
    If Not Dir(strfullpath, vbDirectory) = vbNullString Then DoesFileFolderExist = True
    End Function
    
    Function GetActualFolderName(StartOfPath As String, StartOfFuzzyFolder As String)
    'sourced & modified from http://www.themssforum.com/ExcelProgramming/parent-folder/
    Dim oFSO As Object
    Dim SubDirectory
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    With oFSO.GetFolder(StartOfPath)
        For Each SubDirectory In .SubFolders
            If UCase(Left(SubDirectory.Name, Len(StartOfFuzzyFolder))) = UCase(StartOfFuzzyFolder) Then
                GetActualFolderName = SubDirectory.Name
                Exit For
            End If
        Next SubDirectory
    End With
    'free memory
    Set oFSO = Nothing
    End Function
    could anyone point me straight please

    the way i have it set out is
    Sub COPYandPRINT()
         Application.ScreenUpdating = False
         Application.DisplayAlerts = False
         ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=False
         
         PORow = PONUMBER.Value + 1
         
         Sheets("PURCHASE ORDER NUMBERS").Range("A" & PORow).Value = PONUMBER
         Sheets("PURCHASE ORDER NUMBERS").Range("B" & PORow).Value = SUPPLIER
         Sheets("PURCHASE ORDER NUMBERS").Range("C" & PORow).Value = xDATE
         Sheets("PURCHASE ORDER NUMBERS").Range("D" & PORow).Value = JOBNUMBER
         Sheets("PURCHASE ORDER NUMBERS").Range("E" & PORow).Value = CUSTOMERNAME
         Sheets("PURCHASE ORDER NUMBERS").Range("F" & PORow).Value = DESCRIPTION
         Sheets("purchase order").Select
         
         
    Dim stOfPath As String
    Dim ActualMidFolder As String
    Dim EndOfNameAndPath As String
    Dim FileNameToSave As String
    Dim JobNum As String
    Dim PONum As String
    Dim SuppliersName As String
    
    'define initial variables (note: the ranges may need to be changed
        JobNum = Range("G23").Value
        PONum = Range("k12").Value
        SuppliersName = Range("b16")
        EndOfNameAndPath = SuppliersName & " Purchase Order " & PONum & Format(Date, " dd.mm.yy") & ".xls"
    
    'test to see if it is stock or PO (?) & define the saving path accordingly
        Select Case UCase(Left(JobNum, 1)) = "J"
            Case True
    'Rob's test path:     stOfPath = "C:\Documents and Settings\HP_Owner\My Documents\"
                stOfPath = Range("B69") & "\"
                'test for any likely folders
                    If Not (DoesFileFolderExist(stOfPath & JobNum & "*")) Then GoTo TheEnd
                'identify the exact folder
                    ActualMidFolder = GetActualFolderName(stOfPath, JobNum) & "\"
                'define rest of file name
                    EndOfNameAndPath = "Docs\" & EndOfNameAndPath
                    FileNameToSave = stOfPath & ActualMidFolder & EndOfNameAndPath
            Case False
                stOfPath = Range("B70") & "\"
                If Not (DoesFileFolderExist(stOfPath)) Then GoTo TheEnd
                    FileNameToSave = stOfPath & EndOfNameAndPath
        End Select
    
    'save the file & finish macro
        ActiveWorkbook.SaveAs Filename:=FileNameToSave
        Exit Sub
    
    TheEnd:
    'warn nothing exists & end the macro
        MsgBox "Macro ending b/c no Folder with the following number exists : " & stOfPath & JobNum & "*", , "FYI"
        Debug.Print stOfPath & JobNum & "*"
    End Sub
    
    Public Function DoesFileFolderExist(strfullpath As String) As Boolean
    'sourced from www.excelguru.ca/node/30 by Ken Puls
    'note it only checks for the existence of the lowest folder (or the file) in the strfullpath string.
    If Not Dir(strfullpath, vbDirectory) = vbNullString Then DoesFileFolderExist = True
    End Function
    
    Function GetActualFolderName(StartOfPath As String, StartOfFuzzyFolder As String)
    'sourced & modified from http://www.themssforum.com/ExcelProgramming/parent-folder/
    Dim oFSO As Object
    Dim SubDirectory
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    With oFSO.GetFolder(StartOfPath)
        For Each SubDirectory In .SubFolders
            If UCase(Left(SubDirectory.Name, Len(StartOfFuzzyFolder))) = UCase(StartOfFuzzyFolder) Then
                GetActualFolderName = SubDirectory.Name
                Exit For
            End If
        Next SubDirectory
    End With
    'free memory
    Set oFSO = Nothing
    
    
    
    
         Range("B16:F19,K17:L20,B23:C24,G23:H24,I23:K24,B28:L57").Select
         Range("B16").Activate
         Selection.ClearContents
         Application.ScreenUpdating = True
         PONUMBER = PONUMBER + 1
         Range("B16").Select
         Application.DisplayAlerts = False
    End Function
    and i get run time error 91
    object variable or with block variable not set
    i click the debug button
    and in yellow is this line

    PORow = PONUMBER.Value + 1
    Last edited by stevesunfold; 10-22-2008 at 05:33 PM.

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