Guest User

Untitled

a guest
Jan 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Dim FName As String
  2. Dim FPath As String
  3.  
  4. FPath = "G:"
  5.  
  6. FName = Sheets("sheet 1").Range("A1").Text
  7.  
  8. ThisWorkbook.SaveAs Filename:=FPath & "" & FName
  9.  
  10. Dim FName As String
  11. Dim FPath As String
  12.  
  13. FPath = "G:"
  14.  
  15. FName = ThisWorkbook.Sheets("sheet 1").Range("A1").Text 'use ThisWorkbook since you are running from Workbook1
  16.  
  17. With Workbooks("Workbook2.xlsx")
  18. .SaveAs Filename:=FPath & "" & FName
  19. .Close True '-> use false to not save changes
  20. End With
  21. 'here you need to tell VBA what specific workbook you want to save
  22. 'if you used ThisWorkbook here, you would save the workbook where the code runs from, which is Workbook1
  23.  
  24. Dim FName as String, FPath as String
  25. Dim wkb1 as Workbook, wkb2 as Workbook
  26.  
  27. Set wkb1 = ThisWorkbook '-> or Set wkb1 = Workbooks("workbook1")
  28.  
  29. FPath = "G:"
  30. FName = wkb1.Sheets("sheet 1").Range("A1").Text
  31.  
  32. Set wkb2 = Workbooks("workbook2")
  33. With wkb2
  34. .SaveAs Filename:=FPath & "" & FName
  35. .Close True '-> use false to not save changes
  36. End With
  37.  
  38. Workbooks("Workbook2Filename.xls").SaveAs Filename:=FPath & "" & FName
  39.  
  40. Dim FName As String
  41. Dim FPath As String
  42.  
  43. Dim wbBook1 As Workbook
  44. Dim wbBook2 As Workbook
  45.  
  46. Set wbBook1 = ActiveWorkbook
  47. Set wbBook2 = Workbooks("Workbook2Filename.xls") 'assumed workbook 2 is already open
  48.  
  49. FPath = "G:"
  50. FName = wbBook1.Sheets("sheet 1").Range("A1").Text
  51.  
  52. wbBook2.SaveAs Filename:=FPath & "" & FName
  53.  
  54. Set wbBook1 = Nothing
  55. Set wbBook2 = Nothing
Add Comment
Please, Sign In to add comment