Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-16-2011, 04:46 PM
Joe Patrick Joe Patrick is offline How to create a system folder with VB macro? Windows 7 64bit How to create a system folder with VB macro? Office 2007
Advanced Beginner
How to create a system folder with VB macro?
 
Join Date: May 2011
Posts: 33
Joe Patrick is on a distinguished road
Default How to create a system folder with VB macro?

Hi!

I have this code that works from Excel but from Word I get an error 13/type mismatch.

Can anyone help me make this work from Word, please?

Code:
Sub CreateNewFolder()
Dim _
fso As FileSystemObject, _
fol As Folder, _
fol_add As Folder, _
fil As File
Const strFolPath As String = "\\Fileserver\commonh\GROUP\SDF_data_export"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fol = fso.GetFolder(strFolPath)
 
    On Error GoTo Finish
        If Not fso.FolderExists(strFolPath & "\" & ThisDocument.Textbox59.Value) Then
            Set fol_add = fso.CreateFolder(fol.Path & "\" & ThisDocument.Textbox59.Value)
        End If
    End If
 
    Set fso = Nothing
    Set fol = Nothing
 
End Sub

Reply With Quote
  #2  
Old 12-16-2011, 05:13 PM
macropod's Avatar
macropod macropod is offline How to create a system folder with VB macro? Windows 7 64bit How to create a system folder with VB macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Joe,

Clearly, that code isn't simply copied & pasted from Excel, and it's never going to run as is!

Two obvious errors include 'On Error GoTo Finish' - with no 'Finish' label to go to; and two 'End If' statements but only one 'If'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-17-2011, 06:29 AM
Joe Patrick Joe Patrick is offline How to create a system folder with VB macro? Windows 7 64bit How to create a system folder with VB macro? Office 2007
Advanced Beginner
How to create a system folder with VB macro?
 
Join Date: May 2011
Posts: 33
Joe Patrick is on a distinguished road
Default

Hi, Paul,

You're right, of course. Both those lines were removed after I pasted it in Word, I just accidentally left them in here. As you know, if those were the problems, I would have gotten more specific error messaging.

Here's the code I'm using. Thanx for taking a look!

Code:
Sub CreateNewFolder()
Dim _
fso As FileSystemObject, _
fol As Folder, _
fol_add As Folder, _
fil As File
Const strFolPath As String = "\\Fileserver\commonh\GROUP\SDF_data_export"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fol = fso.GetFolder(strFolPath)
 
        If Not fso.FolderExists(strFolPath & "\" & ThisDocument.Textbox59.Value) Then
            Set fol_add = fso.CreateFolder(fol.Path & "\" & ThisDocument.Textbox59.Value)
        End If
 
    Set fso = Nothing
    Set fol = Nothing
 
End Sub
Reply With Quote
  #4  
Old 12-17-2011, 06:52 AM
Joe Patrick Joe Patrick is offline How to create a system folder with VB macro? Windows 7 64bit How to create a system folder with VB macro? Office 2007
Advanced Beginner
How to create a system folder with VB macro?
 
Join Date: May 2011
Posts: 33
Joe Patrick is on a distinguished road
Default

Ugh, new wrinkle... To test, I started with a fresh document and it works. Just doesn't work on the one I need it to work on. Any ideas why that may be? Recreating this doc will be a huge pain in the butt - as you can see - lots of text boxes and lots of other stuff too. Could that be a contributing factor?
Reply With Quote
  #5  
Old 12-17-2011, 02:04 PM
macropod's Avatar
macropod macropod is offline How to create a system folder with VB macro? Windows 7 64bit How to create a system folder with VB macro? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Joe,

I don't get any 'error 13/type mismatch' errors with the revised code, though I do have to modify it for my system (eg no Fileserver or Textbox). Which line generates the error? Have you checked that the Fileserver path is available and that the Textbox has valid content?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a system folder with VB macro? Macro to save as pdf with ability to choose save as folder rvessio Word VBA 4 07-25-2016 12:37 PM
How to create a system folder with VB macro? Launch macro sub after hitting "create pdf" button in word webharvest Word VBA 1 06-29-2011 04:56 PM
Create Custom menu using a macro twnty2 PowerPoint 0 06-29-2011 04:26 PM
How to create macro to paste text after style? Srivas Word 0 03-16-2010 05:28 AM
Cannot create a public folder? gfkbob Outlook 0 01-07-2010 07:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft