简体   繁体   English

TextBox Excel vba中的波斯日期格式

[英]Persian date format in TextBox Excel vba

I am trying to apply Persian date format in text boxes inside some worksheet. 我试图在一些工作表中的文本框中应用波斯日期格式。 The Text boxes now stores the date in format "dd/mm/yyyy hh:mm" And that's a thing that i applied by myself. 文本框现在以“dd / mm / yyyy hh:mm”格式存储日期。这是我自己应用的东西。 But i'm struggling with applying Persian date in these text boxes. 但我正在努力在这些文本框中应用波斯日期。 I recorded some macro when i'm changing date format of cell to Persian, and i was trying to use it on text box but this code does not seem to work properly. 当我将单元格的日期格式更改为波斯语时,我录制了一些宏,并且我试图在文本框中使用它,但此代码似乎无法正常工作。

This is code that i'm using now and it is working properly 这是我现在使用的代码,它正常工作

TextBox1 = Format(TextBox1, "dd/mm/yyyy hh:mm")

and those lines I was trying to use to apply Persian date but I don't get any effect 我试图用这些线来申请波斯日期,但我没有任何效果

TextBox3 = Format(TextBox3, "[$-fa-IR,16]dd/mm/yyyy;@")

And this is the effect of recording macro and changing date format to Persian manually. 这是手动录制宏和更改日期格式到波斯语的效果。 From this line i got a formula and try to implement it above. 从这一行我得到了一个公式,并尝试在上面实现它。

Range("J30").Select
    Selection.numberFormat = "[$-fa-IR,16]dd/mm/yyyy;@"

Does any of you could provide me with some reasonable solution to this? 你们中有谁能为我提供一些合理的解决方案吗?

Thank you in advance for your Help. 预先感谢您的帮助。

Have you installed Persian? 你安装了波斯语吗?

File > Options > Language > [Add additional editing languages] - Select Persian > Add > OK 文件>选项>语言> [添加其他编辑语言] - 选择波斯语>添加>确定

You will probably need to restart Excel and may need to re-apply the formatting. 您可能需要重新启动Excel,可能需要重新应用格式。

This blog post should be of help to you as it covers a number of different date formats, including Persian https://www.jquery-az.com/3-ways-change-date-format-excel-14-date-formulas/ 这篇博文应该对您有所帮助,因为它涵盖了许多不同的日期格式,包括波斯语https://www.jquery-az.com/3-ways-change-date-format-excel-14-date-formulas /

In excel, the following formula will format a standard date in Persian: 在excel中,以下公式将格式化波斯语的标准日期:

=TEXT(A1,"[$-0429]mmmm d,yyyy")

So in VBA, the following should work: 所以在VBA中,以下应该有效:

Range("J30").numberFormat = "[$-0429]mmmm d, yyyy"

In terms of formatting within a text box, providing the textbox text is referring to a cell location, formatting this cell location will impact on the format of the textbox - see illustration below. 在文本框中的格式设置方面,提供文本框文本是指单元格位置,格式化此单元格位置将影响文本框的格式 - 请参见下图。

在此输入图像描述

If you are trying to format text directly within the textbox you might try adding .value to your code snippet above eg. 如果您尝试直接在文本框中设置文本格式,可以尝试将.value添加到上面的代码段中,例如。

TextBox3.value = Format(TextBox3.value, "[$-fa-IR,16]dd/mm/yyyy;@")

I only have access to Office for Mac at work and that feature is not supported for me to test. 我只能在工作时访问Office for Mac,并且我不支持该功能进行测试。 This blog post discusses how to apply formatting to text boxes via VBA but it may not support language formatting options. 此博客文章讨论了如何通过VBA将格式应用于文本框,但它可能不支持语言格式选项。 If thats the case you may consider amending your text boxes to reference a cell location that you can format. 如果是这种情况,您可以考虑修改文本框以引用可以格式化的单元格位置。

https://www.extendoffice.com/documents/excel/4899-excel-format-textbox-as-currency.html https://www.extendoffice.com/documents/excel/4899-excel-format-textbox-as-currency.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM