Results 1 to 4 of 4

Thread: Copy workbook to folder created.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Copy workbook to folder created.

    u can atleast help me in this.



    While mailing a sheet i want to copy that sheet contents to a temporary created workbook with same name as of selected workbook. and store this temp workbook in the folder which i have created.The problem is how will i store the copy of selected workbook to that folder which i have created.





    In the following code:



    1)list.text --- is name of the sheet.

    2)activeworkbook.name--- i tested with f8 dosn't gives name

    3)activesheet.copy-- tested with f8 dont give anything

    4).Attachments.Add Wb.FullName--givin path of the sheet selected.

    5) Kill Wb.FullName--destroys the copy of workbook creted in mydocuments.



    I want this copy of workbook to save in the folder created by me.

    VB Code:
    1. Application.ScreenUpdating = False
    2.     Set OL = CreateObject("Outlook.Application")
    3.     Set EmailItem = OL.CreateItem(olMailItem)
    4.     fileName = List1.Text '& " - "  & ActiveWorkbook.name
    5.     Debug.Print fileName
    6.    
    7.     For y = 1 To Len(fileName)
    8.         TempChar = Mid(fileName, y, 1)
    9.         Select Case TempChar
    10.         Case Is = "/", "\", "*", "?", """", "<", ">", "|", ":"
    11.         Case Else
    12.             SaveName = SaveName & TempChar
    13.         End Select
    14.     Next y
    15.     ActiveSheet.Copy
    16.     Set Wb = ActiveWorkbook
    17.     Wb.SaveAs SaveName
    18.     Wb.ChangeFileAccess xlReadOnly
    19.     With EmailItem
    20.         .Subject = txtsubject
    21.         .Body = txtmessage
    22.         .To = Txtname
    23.         .Attachments.Add Wb.FullName
    24.         .Send
    25.     End With
    26.     Kill Wb.FullName
    27.     Wb.Close False
    28.      
    29.     Application.ScreenUpdating = True
    30.      
    31.     Set Wb = Nothing
    32.     Set OL = Nothing
    33.     Set EmailItem = Nothing
    34.    
    35.     End If





    If there is any unnecess. code plz tell me......

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Copy workbook to folder created.

    You could try saving the file as normal and then using a one line piece of code that will then copy the file to the temporary location..

    VB Code:
    1. FileCopy ActiveWorkbook.FullName, "C:\Temp Folder\" & ActiveWorkbook.Name

    Your code can then be changed to the following..

    VB Code:
    1. Application.ScreenUpdating = False
    2.   Set OL = CreateObject("Outlook.Application")
    3.   Set EmailItem = OL.CreateItem(olMailItem)
    4.   Set Wb = ActiveWorkbook
    5.   Wb.ChangeFileAccess xlReadOnly
    6.   Wb.Save
    7.   FileCopy Wb.FullName, "C:\Temp Folder\" & Wb.Name
    8.   Wb.ChangeFileAccess xlReadWrite
    9.   Wb.Save
    10.   With EmailItem
    11.     .Subject = txtsubject
    12.     .Body = txtmessage
    13.     .To = Txtname
    14.     .Attachments.Add "C:\Temp Folder\" & Wb.Name
    15.     .Send
    16.   End With
    17.   On Error Resume Next
    18.   Kill "C:\Temp Folder\" & Wb.Name
    19.   Wb.Close False
    20.   Application.ScreenUpdating = True
    21.   Set Wb = Nothing
    22.   Set OL = Nothing
    23.   Set EmailItem = Nothing
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: Copy workbook to folder created.

    the answer is almost in your own code, that is if I'm understanding you correct.

    Code:
    Wb.SaveAs SaveName
    if left$(YourPath,1) = "\" then
         Wb.SaveAs YourPath & SaveName
    else
         Wb.SaveAs YourPath & "\" & SaveName
    end if
    The var Yourpath is the path to your created directory like "C:\Progam Files\MyApp\ThisMailAdress\SendWorkBooks\"
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: Copy workbook to folder created.

    how can i destroy the folder created?

Posting Permissions

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



Click Here to Expand Forum to Full Width