Results 1 to 10 of 10

Thread: Spaces in HTML

  1. #1
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Spaces in HTML

    Hi all,

    This is most likely a simple question, but it's stumped my limited understanding of html.

    I'm trying to use code that I was directed to in this forum to start Word with a new doc based on a template. Here's the code:
    <script language="vbscript">
    Sub MakeNew(strTemplate)

    On Error Resume Next

    Dim oshell

    Set oshell = CreateObject("Wscript.Shell")

    ' If "winword.exe /ttemplate.dot" doesn't work, you can try Plan B, which

    ' is to shell the template name and add the below AutoOpen macro to the template

    oshell.Run "winword.exe /t" & strtemplate

    Set oshell = Nothing

    End Sub

    </script>



    To create a new document based on test.dot,

    <SPAN onClick=MakeNew("F:appsoffice2000PFilesMSOfficeTem plateWTWfaxtrans.dot")

    STYLE="font-weight: bold;cursor: hand;">click here</SPAN>.</p>


    Runs fine, except in reality, both the file name of the template and the folder contain spaces. The effect is that Word starts, but does not open the template. If I change the name and path to remove the spaces, the call works. Of course, if I leave the spaces in the string, it generates a compile time error. However, if I replace the spaces with 's, like so:

    onClick=MakeNew("F:appsoffice2000PFilesMSOfficeTem plateWTW StdsWTW fax trans.dot"

    It fails to open the correct template (just the default template), or Word gives me an error message to the effect that I haven't specified a valid file.

    Can someone give me some guidance on getting this to parse properly?

    Thank you very much
    Jim Helfer

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Spaces in HTML

    Jim, I believe Bryan used the % 20 code (if I delete the space between % and 20 it turns into a space!).

    I don't know if that will work. Try experimenting with quotation marks around the entire shell expression (using Start>Run... is a good way) until you find an approach that will work for any template name.. "There must be a way!"

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spaces in HTML

    Yea I did.

    It's funny I could have sworn % 20 (without the space) was there when I previewed and posted.

    I guess it just goes to show that you see what you want to see and not what's there.

    I'll edit the post to make it more understandable. <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spaces in HTML

    <P ID="edit" class=small>(Edited by carbonnb on 17-Jun-03 05:49. To make the % 20 visible)</P>Jim,

    Try replacing the spaces with % 20 (without the space).

    So your onClick=MakeNew("F:appsoffice2000PFilesMSOfficeTem plateWTW StdsWTW fax trans.dot" line would look like:

    onClick=MakeNew("F:appsoffice2000PFilesMSOfficeTem plateWTW% 20StdsWTW% 20fax% 20trans.dot"
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spaces in HTML

    Oh, I'm sorry. I was not clear.

    I understand the use of the " % 20 " as a space, however when I try to use it, it's not working for me. Hoping I was missing some obvious gotcha rather than having to divine the mind of the parser :-(.

    I _ask_ them not to use spaces in things. They never listen :-(

  6. #6
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spaces in HTML

    Other than % 20 I have no other ideas. Sorry.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Spaces in HTML

    You need to come up with the right string for Windows' Start>Run... line. If you paste in:

    F:appsoffice2000PFilesMSOfficeTemplateWTW StdsWTW fax trans.dot

    What happens? Try experimenting with " marks around various things until it works, and then insert those back into your code. (As you may know, use "" (quote quote) for a quotation mark in VBScript.)

  8. #8
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spaces in HTML

    I added a 'msgbox' statement to the function to see what the function was getting, and it turns out that it's a catch-22. HTML demands that the special char be used , but VBscript doesn't seem to know about it and takes it as a literal.

    For example, the path:

    C:new tempwtwtest.dot

    Must be represented in the HTML as :

    makenew("c:new tempwtwtest.dot")

    However, in the makenew(str) function, this string is passed literally, so:

    Str = "C:new tempwtwtest.dot"

    At least that's the way it looks to my novice gaze.

    Jim

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Spaces in HTML

    Try using real spaces but changing your onClick event handler code as follows:

    <pre>onClick="MakeNew('F:appsoffice2000PFilesMSOff iceTemplateWTW StdsWTW fax trans.dot')"</pre>

    I think this has a better chance of passing the path unscathed to your function.

  10. #10
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Spaces in HTML

    Excellent!

    I would not have figured out that the Makenew() statement would ever need " " 's . It's working now after I added one more step, the /tswitch on the shell command needed additinal quote delimiters!

    Oh well, a day spent learning about quotation marks is a day well spent, I suppose.


    Thanks for everybody's assistance!

    Jim Helfer

Posting Permissions

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