Advertisement
Guest User

Untitled

a guest
May 9th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. Sub ZmieńRozszerzenia()
  2. On Error GoTo ZmieńRozszerzenia_Error
  3.  
  4. Dim objFSO As Object 'Scripting.FileSystemObject
  5. Dim objFolder As Object 'Scripting.Folder
  6. Dim objFile As Object 'Scripting.File
  7. Dim xlApp As Excel.Application
  8. Dim wkb As Excel.Workbook
  9. Dim strXLSName As String
  10.  
  11. Const strFolderName As String = "C:\Documents and Settings\steo\Pulpit\pliki"
  12.  
  13.  
  14. Set xlApp = New Excel.Application
  15. With xlApp
  16. .EnableEvents = False
  17. .DisplayAlerts = False
  18. End With
  19.  
  20. Set objFSO = VBA.CreateObject("Scripting.FileSystemObject")
  21. Set objFolder = objFSO.GetFolder(strFolderName)
  22.  
  23. For Each objFile In objFolder.Files
  24. With objFile
  25. If .Name Like "*.xlsm" Then
  26. strXLSName = Left(.Name, Len(.Name) - 1)
  27. Set wkb = xlApp.Workbooks.Open(.Path)
  28. With wkb
  29. .SaveAs Filename:=strFolderName & "\" & strXLSName, _
  30. FileFormat:=xlExcel8
  31. .Close SaveChanges:=False
  32. End With
  33. Set wkb = Nothing
  34. VBA.Kill .Path
  35. End If
  36. End With
  37. Next
  38.  
  39. MsgBox "steo mowi, ze dziala", vbInformation
  40.  
  41. ZmieńRozszerzenia_Exit:
  42. On Error Resume Next
  43. If Not wkb Is Nothing Then
  44. wkb.Close SaveChanges:=False
  45. Set wkb = Nothing
  46. End If
  47. If Not xlApp Is Nothing Then
  48. xlApp.Quit
  49. Set xlApp = Nothing
  50. End If
  51. Set objFolder = Nothing
  52. Set objFSO = Nothing
  53. Exit Sub
  54.  
  55. ZmieńRozszerzenia_Error:
  56. MsgBox "Unexpected error - " & Err.Number & vbCrLf & vbCrLf & _
  57. Err.Description, vbExclamation, "VBAProject - ZmiRoz"
  58. Resume ZmieńRozszerzenia_Exit
  59. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement