Consulting

Results 1 to 3 of 3

Thread: Alternate way to move a file

  1. #1
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location

    Alternate way to move a file

    Hi everyone,

    Using some code I found online and changing it up a little I was almost able to make my code do what I needed. My problem come in the line:

    Name "Z:\Site_MEA\MEA ECC Exclusions\MEA_ECC_EX "&wo&".doc" As "Z:\Site_MEA\MEA ECC Exclusions\Approved MEA_ECC EX\MEA_ECC_EX "&wo&".doc"

    I added this line to move a file based on a WorkOrder number (wo) (taken from a cell in the first column) to another location. My code will works perfectly if I manually change out the "&wo&" for a real number like 1234 but if I use the code how it is now, it doesn't work. Note: the value wo will keep changing based on what row it is at. The big problem that I have is the other macro will stop working properly when I run this code, it will not show any errors but it does not populate the sheet from word docs like it is suppose to.

    Below you can see my code for this macro. Am I maybe missing a line that I should put in or is there another easy way to move a file.

    Any help would be great.
    David

    Sub Approve_Selected_ECC_Exclusion()
    Dim Check As Range, r As Long, lastrow2 As Long, lastrow As Long
    Dim wo As String
    Application.ScreenUpdating = False
    lastrow = Worksheets("Open ECC_EX").UsedRange.Rows.Count
    lastrow2 = Worksheets("Approved ECC_EX").UsedRange.Rows.Count
    If lastrow2 = 1 Then lastrow2 = 0
    For r = lastrow To 2 Step -1
    If Range("I" & r).Value = "approved" Then
    wo = Range("A" & r).Text
    Name "Z:\Site_MEA\MEA ECC Exclusions\MEA_ECC_EX "&wo&".doc" As "Z:\Site_MEA\MEA ECC Exclusions\Approved MEA_ECC EX\MEA_ECC_EX "&wo&".doc"
    Rows(r).Cut Destination:=Worksheets("Approved ECC_EX").Range("A" & lastrow2 + 1)
    lastrow2 = lastrow2 + 1
    Worksheets("Open ECC_EX").Rows(r).Delete
    Else:
    End If
    Next r
    Application.ScreenUpdating = True
    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Quick guesses ... (and ONLY guesses)

    1. You need a 2 backslashes after each MEA_ECC_EX if that is a folder
    2. You need spaces around the &'s

    Name "Z:\Site_MEA\MEA ECC Exclusions\MEA_ECC_EX\" & wo & ".doc" As _
    
              "Z:\Site_MEA\MEA ECC Exclusions\Approved MEA_ECC EX\MEA_ECC_EX\" & wo & ".doc"
    ---------------------------------------------------------------------------------------------------------------------

    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

  3. #3
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location
    Hi,

    I tried the spaces around the &'s and it seems to work right now (hopefully it stays that way.) Didn't think that would make a difference.

    Thanks
    David

Posting Permissions

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