Dansk Regneark Forum
  Hjælp Hjælp  Søg i forum   Arrangementer   Opret ny bruger Opret ny bruger  Log ind Log ind


Emne lukketFiler/Folders på Mac

 Besvar Besvar
Forfatter
jespergn Se dropdown
Bronze bruger
Bronze bruger
Avatar

Medlem: 23.Sep.2014
Status: Offline
Point: 90
Direkte link til dette indlæg Emne: Filer/Folders på Mac
    Sendt: 10.Jan.2015 kl. 14:12
Hej.

Jeg skal lave en VBA der laver to folders som jeg godt kan finde ud af:

MkDir (ThisWorkbook.Path & Application.PathSeparator & "Folder1")
MkDir (ThisWorkbook.Path & Application.PathSeparator & "Folder2")

Jeg ved at disse bliver gemt i mappen overførsler. Men hvorfor??

Nå, men derefter skal jeg via en inputbox skulle kunne lave en subfolder, under folder1 eller folder2.

Inputboxen skal stille to spørgsmål fx. "Navn" og "alder." 

"Navn" skal være det nye navn på den nye folder.

Hver gang der bliver oprettet en ny folder skal den indeholder tre excel-filer med evt. "Fil1" "Fil2" og "Fil3"

Derudover skal der i alle filerne skrives "Navn" og "Alder" fra input boxen i celle A1 og A2.

Nogle der kan hjælpe?
Til top



Til top
jespergn Se dropdown
Bronze bruger
Bronze bruger
Avatar

Medlem: 23.Sep.2014
Status: Offline
Point: 90
Direkte link til dette indlæg Sendt: 10.Jan.2015 kl. 16:54
Har løst problemet med følgende kode:

Option Explicit

Function CheckIfFolderExists(s As String) As Boolean
    On Error Resume Next
    GetAttr (ThisWorkbook.Path & Application.PathSeparator & s)

    If Err.Number = 0 Then
        CheckIfFolderExists = True
    Else
        CheckIfFolderExists = False
    End If
    
    On Error GoTo 0 ' turns of Error Resume next
End Function


Public Sub Ex12_8()

If CheckIfFolderExists("Employees") = True Then
    MsgBox "The folder already exists"
    Else
        MkDir (ThisWorkbook.Path & Application.PathSeparator & "Employees")
    End If

If CheckIfFolderExists("FormerEmployees") = True Then
    MsgBox "The folder already exists"
    Else
        MkDir (ThisWorkbook.Path & Application.PathSeparator & "FormerEmployees")
    End If

End Sub

Public Sub Ex12_9()
Dim name As String
Dim begindate As Date
Dim W As Workbook
Dim strPath As String
Dim stPath As String
   
strPath = ThisWorkbook.Path & Application.PathSeparator & "Employees"

name = InputBox("Type the name of the new employee:")
MkDir (strPath & Application.PathSeparator & name)

begindate = InputBox("Type the start date of " & name)

stPath = strPath & Application.PathSeparator & name



    Set W = Workbooks.Add
    W.Worksheets("Sheet1").Range("A1") = name
    W.Worksheets("Sheet1").Range("A2") = begindate
    W.SaveAs Filename:=stPath & Application.PathSeparator & "PersonalData"
    W.Close

    Set W = Workbooks.Add
    W.Worksheets("Sheet1").Range("A1") = name
    W.Worksheets("Sheet1").Range("A2") = begindate
    W.SaveAs Filename:=stPath & Application.PathSeparator & "Training"
    W.Close

    Set W = Workbooks.Add
    W.Worksheets("Sheet1").Range("A1") = name
    W.Worksheets("Sheet1").Range("A2") = begindate
    W.SaveAs Filename:=stPath & Application.PathSeparator & "Salary"
    W.Close

End Sub



Men nu skal jeg have lavet en sub der gør det muligt at flytte de folders der hedder "Name" fra "Employees" til "FormerEmployees"

Windows versionen ser sådan ud:

Sub Exercise12_10()
    Dim sys As FileSystemObject
    Dim f As Folder
    Dim Name As String ' name of employee
 
    Set sys = New FileSystemObject

    Name = InputBox("Please enter the name of the employee whos employment stops:")

    Set f = sys.GetFolder(ThisWorkbook.Path & "\Employees\" & Name)

    f.Move (ThisWorkbook.Path & "\FormerEmployees\" & Name)
End Sub
Til top
 Besvar Besvar

Skift forum Forum tilladelser Se dropdown

© 2010 - 2024 Dansk Regneark Forum - en del af Excel-regneark.dk